需要關於這個簡單代碼的幫助,我應該替換哪些代碼 $users = User::all();
所以我可以有條件地鏈接作用域方法並在最後對它進行分頁?Laravel 5雄辯的條件鏈查詢
我試着用$users = new User();
啓動User
對象,出現錯誤,試圖在VIEW
上使用時得到非對象錯誤的屬性。
public function index()
{
// user search
$name = $this->request->name;
$email = $this->request->email;
$users = User::all();
if (!empty($name)) {
$users->name($name);
}
if (!empty($email)) {
$users->email($email);
}
$users->paginate(5);
return view('admin.users.index',compact('users'));
}
在此先感謝
你想顯示所有用戶? –
我想在管理員點擊搜索按鈕時按名稱或電子郵件過濾用戶 – cyberfly