How to concatenate columns with Laravel 4 Eloquent?

后端 未结 4 1650
长情又很酷
长情又很酷 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 13:54

    lists() method used to select column from selected result. So first contact first name and last name and give this column with new alias name in select statement

     $tenants = Tenant::orderBy('First_Name')->select(DB::row('CONCAT(`First_Name`," ",`Last_Name`) as name'),'Tenant_Id')->lists('name', 'id');
    

    then you can select this alias in lists() method

提交回复
热议问题