这是一个简化的用例,只是为了说明我想要实现的目标:
Considering this query in pure SQL:
SELECT url, 1 AS active
FROM `modules`
WHERE 1
How can I add the constant active column using query builder ?
这是我的查询生成器,没有额外的列:
DB::table('modules')
->get(['url']);
这是一个简化的用例,只是为了说明我想要实现的目标:
Considering this query in pure SQL:
SELECT url, 1 AS active
FROM `modules`
WHERE 1
How can I add the constant active column using query builder ?
这是我的查询生成器,没有额外的列:
DB::table('modules')
->get(['url']);
Simplest would be to use DB::raw
DB::table('modules')->get(['url', DB::raw('1 as active')]);