laravel 使用mysql CASE进行自定义排序

laravel 使用mysql CASE进行自定义排序

$aimclient = $aimclient->
    select(DB::raw("*,CASE WHEN first_status = 1 
    and status = 2 THEN 1 WHEN first_status = 2
    and status = 3 THEN 2 WHEN first_status = 2 
    and status = 4 THEN 2 END as status_sort"))
    ->where(function ($query) {
           $query->where(function ($query) {
            $query->where('first_status', 1)->where('status', 2);
    })->orWhere(function ($query) {
            $query->where('first_status', 2)->where('status', 3);
    })->orWhere(function ($query) {
            $query->where('first_status', 2)->where('status', 4);
    });
    })->with('order')->orderBy('status_sort', 'asc')
      ->paginate($pagezise);