How to concatenate columns with Laravel 4 Eloquent?

后端 未结 4 1490
长情又很酷
长情又很酷 2021-01-30 13:16

I have a table called tenantdetails which contains

Tenant_Id | First_Name | Last_Name | ........

and I want to retrieve Firs

4条回答
  •  佛祖请我去吃肉
    2021-01-30 14:02

    You should use the DB::raw() to concat those of field

    Tenant::select(
              'Tenant_Id',
              DB::raw('CONCAT(First_Name,"-",Last_Name) as full_name')
    
            )
           ->orderBy('First_Name')
           ->lists('full_name', 'Tenant_Id');
    

提交回复
热议问题