swapnil mane
swapnil mane

Reputation: 257

Call to a member function links() on array in laravel 8 with pagination

I am getting this error while paginating from one page to another page. when I click on the 2 number link following error occurs.

Call to a member function links() on array FUNCTION

 $data = tbl_company::query()
                ->where(
                    "company_name",
                    "LIKE",
                    "%{$req->company_name}%"
                )->paginate(100);
            return view('/admin/company/index', compact('data', 'showPagination'));

BLADE.FILE

 {{$data->links()}}

Upvotes: 1

Views: 2040

Answers (3)

Snapey
Snapey

Reputation: 4110

In the controller, append the query data that you need (not the whole request object)

 $data = tbl_company::query()
                ->where(
                    "company_name",
                    "LIKE",
                    "%{$req->company_name}%"
                )
                ->paginate(100)
                ->withQueryString();

            return view('/admin/company/index', compact('data', 'showPagination'));

https://laravel.com/docs/9.x/pagination#appending-query-string-values

Upvotes: 2

swapnil mane
swapnil mane

Reputation: 257

I solved this question after modifying blade file

I changed code

from

{{$data->links()}}

to

 {!! $data->appends(Request::all())->links() !!}

Upvotes: 0

Gran
Gran

Reputation: 157

Try This

{!! $data->render() !!}

Upvotes: 1

Related Questions