Laravel 模型列表方法返回列的所有值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19215879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:31:54 来源:igfitidea点击:
Laravel Model lists method return all the value of the column
提问by caoglish
a model defined like this:
一个像这样定义的模型:
class Model extends Eloquent {
protected $table='model';
}
then I query like:
然后我查询如下:
$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'];
so, I though the lists method should only contains array which only has ids was found. why it has all the id of model table.
所以,我虽然lists方法应该只包含只找到id的数组。为什么它具有模型表的所有 id。
and which Class API in Laravel API doc I should look after?
我应该关注 Laravel API 文档中的哪个类 API?