您需要将查询包装在
DB::raw:
$comp = Component::select(DB::raw("CONCAt('name','id') AS ID"))->get()另外,请注意,因为您正在执行这样的查询,所以模型的行为可能会有所不同,因为此选择会从select语句中删除所有其他字段。因此,如果没有新的查询,就无法从模型中读取其他字段。因此,仅将其用于读取数据而不是修改数据。
另外,为了使其列表更好,我建议您将查询修改为:
$comp = Component::select(DB::raw("CONCAt('name','id') AS display_name"),'id')->get()->pluck('display_name','id');// dump output to see how it looks.dd($comp);// array key should be the arrray index, the value the concatted value.


