如何在Laravel Eloquent中连接列?

如何在Laravel Eloquent中连接列?,laravel,eloquent,Laravel,Eloquent,考虑到此客户表包含以下列: 名字 中间名 苏鲁名字 延伸 因此: 我提出了这个原始的问题: $customer = DB::select("select c.* from customers c where concat_ws(', ' ,c.sur_name,concat_ws(' ',concat_ws(' ',c.first_name,c.middle_name),c.extension)) like ?", [$item]); 如何将其转换为模型库,例如处理空值的Customer:

考虑到此客户表包含以下列:

  • 名字
  • 中间名
  • 苏鲁名字
  • 延伸
因此:

我提出了这个原始的问题:

$customer = DB::select("select c.* from customers c where concat_ws(', ' ,c.sur_name,concat_ws(' ',concat_ws(' ',c.first_name,c.middle_name),c.extension)) like ?", [$item]);
如何将其转换为模型库,例如处理空值的
Customer::where()->first()
(在mysql的情况下为concat_ws)?

尝试下面的代码

 $costomers = Customer::select(DB::raw("CONCAT('first_name','last_name') AS Name"))->get();

希望你能帮忙

我认为这不是在处理数据库中的空值。如果您使用该链接中建议的属性getter,那么您将提取所有数据(无论是否为空),然后使用模型属性进行连接。
 $costomers = Customer::select(DB::raw("CONCAT('first_name','last_name') AS Name"))->get();