MKJ MKJ - 1 month ago 8x
Ajax Question

How can I Send Search and Get Data Back with Laravel 5 Paginator

I'm using Laravel 5 to paginate my data, it works well. Now it shows me 10 records out of hundreds. Now I want to search records not from the present on the page (which are only 10), but from the db and it should be displayed on my page.

How can I do this?
Any help please!!!

Note: I'm using dataTableJs library as well, but it looks not good. It loads all the data then makes its pagination on client. This is also not good.


In your controller

use DB;


$r = DB::table('your table');
// your query for exemple
$results = $r->paginate(10);
return view('yourview',['results'=>$results]);

in your blade

 @foreach ($results as $result)
        {{ $result->Anycolumn; }}


to pass $_GET in your pagination

in controller q: name of your input

$q= $request->get('q');
     return view('yourview',['results'=>$results,'q'=>$q]);

in blade