如何使用 Laravel 5 分页器发送搜索并取回数据

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

我正在使用 Laravel 5 对我的数据进行分页,效果很好。现在它显示了数百条记录中的 10 条。现在我想搜索的记录不是从页面上的当前(只有 10 条),而是从数据库中搜索,它应该显示在我的页面上。

我该怎么做? 请帮忙!!!

注意:我也在使用 dataTableJs 库,但它看起来不太好。它加载所有数据,然后在客户端进行分页。这也不好。

在你的控制器中

use DB;

之后

$r = DB::table('your table');
// your query for exemple
$r->select('*')->where('column','like','%value%');
$results = $r->paginate(10);
return view('yourview',['results'=>$results]);

在你的 blade

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

{{$results->links()}}

在您的分页中传递 $_GET

在控制器中 q: 您输入的名称

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

在blade

{{($results->appends(Request::only(['q']))->links())}}