$students=student::get();//获取模型所有数据?
dd($students);
与
$students=student::all();//查询模型所有数据?
dd($students);
这两者有什么区别呢?
阿神2017-01-11 11:45:25
查阅Model源码可得
public static function all($columns = ['*']) { $columns = is_array($columns) ? $columns : func_get_args(); $instance = new static; return $instance->newQuery()->get($columns); }
而newQuery()得到的是是一个Builder类
all()不传参有默认值*,继而调用get();
get()位于Illuminate\Database\Eloquent\Builder中
同样有默认值*
public function get($columns = ['*']) { $builder = $this->applyScopes(); $models = $builder->getModels($columns); if (count($models) > 0) { $models = $builder->eagerLoadRelations($models); } return $builder->getModel()->newCollection($models); }
故得证