Laravel模型列表方法返回列的所有值


Laravel Model lists method return all the value of the column

一个定义如下的模型:

class Model extends Eloquent {
        protected $table='model';
    }

然后我像这样查询:

$model=Model::find(2);
$model->id;//return 2;
$model->lists('id');//return array contains all the ids in model table like ['1','2','3',...]. not ['2'];

所以,我虽然列表方法应该只包含只有 id 的数组。 为什么它有模型表的所有 ID。

以及我应该照顾 Laravel API 文档中的哪个类 API?

根据文档,列表函数获取表的列值列表。以这种方式调用它实质上是在运行一个全新的查询。