📜  laravel 使用分页搜索和返回记录 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:47.809000             🧑  作者: Mango

代码示例1
//make sure that all your queries/builder has ->paginate and not a ->get() or 
//->first() then do {{ $var->links() }} in the blade

        if(empty($request->search)){
            $user = DB::table('users')->Paginate(15);
            return view('/users', ['user' => $user]);
        }else{
            $user = DB::table('users')->where('name', 'like', '%'. $request->search .'%')->Paginate(15);
            return view('/users', ['user' => $user]);
        }