Laravel为查询生成器提供带有list()函数
就您而言,您可以替换代码
$items = Items::all(['id', 'name']);
与
$items = Items::lists('name', 'id');另外,您也可以将其与其他查询生成器链接在一起。
$items = Items::where('active', true)->orderBy('name')->lists('name', 'id');来源:http :
//laravel.com/docs/5.0/queries#selects
Laravel 5.2的更新
非常感谢@jarry。如您所述,Laravel 5.2的功能应为
$items = Items::pluck('name', 'id');要么
$items = Items::where('active', true)->orderBy('name')->pluck('name', 'id');参考:https :
//laravel.com/docs/5.2/upgrade#upgrade-5.2.0-
查看弃用列表



