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

Time:08-13

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()}}

CodePudding user response:

Try This

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

CodePudding user response:

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

CodePudding user response:

I solved this question after modifying blade file

I changed code

from

{{$data->links()}}

to

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