harish_sng harish_sng - 3 years ago 106
PHP Question

fetching null value in php framework, laravel query builder

i need laravel query builder to fetch '' as gdate to do union of another query.

example below:

$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');

Answer Source

You could make use of 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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download