如何在Laravel中进行分页搜索

时间:2016-08-26 09:16:26

标签: php laravel-5

在laravel我只有分页,但我想要搜索分页。

这是我的分页代码。

$leads = DB::table('leads')->join('states','leads.state','=','states.id')->join('districts','leads.district','=','districts.id')->join('users','leads.userid','=','users.id')->select('leads.*','states.name as sname','districts.name as dname','users.name as uname')->orderBy('leads.id', 'desc')->paginate(10);

我尝试过搜索分页,但它无法正常工作。

这是我的代码:

$leads = DB::table('leads')->join('states','leads.state','=','states.id')->join('districts','leads.district','=','districts.id')->join('users','leads.userid','=','users.id')->select('leads.*','states.name as sname','districts.name as dname','users.name as uname')->where('leads.phoneno', 'like', "%$search%")->paginate(10);

任何人都可以帮助我解决我犯错误的地方吗?

1 个答案:

答案 0 :(得分:0)

试试这个

$leads = DB::table('leads')->join('states','leads.state','=','states.id')->join('districts','leads.district','=','districts.id')->join('users','leads.userid','=','users.id')->select('leads.*','states.name as sname','districts.name as dname','users.name as uname')->where('leads.phoneno', 'like', '%'.$search. '%')->paginate(10);