Laravel - Add custom column in select with Eloquent query buider

前端 未结 3 969
北荒
北荒 2021-01-07 22:11

this is a simplified use case, only to illustrate what I want to achieve:

Considering this query in pure SQL:

SELECT url, 1 AS active
FROM  `modules`         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-07 22:45

    Simplest would be to use DB::raw

         DB::table('modules')->get(['url', DB::raw('1 as active')]);
    

提交回复
热议问题