我正在使用 Laravel.5.3,以下是我的查询
$ProjectManagers = Employees::where("designation" , 1)
->pluck(DB::raw('CONCAT(first_name," ",last_name) AS name'),'id');
这引发了一个错误
Illegal offset type in isset or empty
我可以知道这是否是正确的方法吗?
如果我不使用联系人并使用类似
$ProjectManagers = Employees::where("designation" , 1)->pluck('first_name','id');
这是工作正确并给我结果
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[8] => Punit
)
)
预期结果:
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[8] => Punit Gajjar
)
)
其中名字和姓氏连接在一起。
最佳答案
尝试将 eloquent 查询更改为:
$ProjectManagers = Employees::select(
DB::raw("CONCAT(first_name,' ',last_name) AS name"),'id')
->where('designation', 1)
->pluck('name', 'id');
关于php - Laravel 使用 concat with pluck 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40132046/