Laravel 框架之數據庫相關操作

//查詢列表加模糊條件查詢

$find //查詢條件數組

$perPage //顯示條數

$page //顯示第幾頁

$field //排序字段

$order //排序規則

$user = DB::table('system_user')->where(function ($query) use ($find) {
    isset($find['user_name']) && $query->where('user_name', 'like', '%' . $find['user_name'] . '%');
    })->orderBy($field,$order)->paginate($perPage,$page);//查詢分頁列表
$user->total();//總數據條數
$data = $user->items();//輸出成數組

//查詢數據    鍵值對   例如:ID=>role_name

$roles = DB::table('system_role')->pluck('role_name', 'id');
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章