2017-07-26 51 views
0

我需要laravel查詢構建器來獲取''作爲gdate來做另一個查詢的聯合。在php框架中獲取空值,laravel查詢構建器

下面的例子:

$unionquery = DB::table('mt_task_category') 
->whereIn('role_id', [1]) 
->select('null as gdate', 'null as user_id', 
     'category_id', 'category_name', 
     'null AS timeSum', 'null AS gdfullname', 
     'null AS id', 'null AS pmfullname', 'null AS role_name'); 

回答

1

你可以利用DB::raw()

$unionquery = DB::table('mt_task_category') 
       ->select(DB::raw('null AS gdate', 'null AS user_id', 
         'category_id', 'category_name', 
         'null AS timeSum' , 'null AS gdfullname', 
         'null AS id', 'null AS pmfullname', 
         'null AS role_name')); 
       ->whereIn('role_id', [1]) 
       ->get();