Tin*_*tin 1 php laravel eloquent
根据laravel docs,take()只是limit()的别名.
为什么不查询no 4不起作用,而其他工作就好了.
1. $employee->take(2)->get(); // Works
2. $employee->limit(2)->get(); // Works
3. $employee->get()->take(2); // Works
4. $employee->get()->limit(2) // Gives Error; Method Illuminate/Database/Eloquent/Collection::limit does not exist.
Run Code Online (Sandbox Code Playgroud)
当你打电话get
,你的数据库查询被执行,所以结果是Illuminate\Support\Collection
,当你打电话limit
的Collection
,因为引发错误Collection
类不具有limit
的功能.
limit
并且take
都在你的数据库查询,因为它们是两个函数执行Illuminate\Database\Query\Builder
和Illuminate\Database\Eloquent\Builder
也,不上Collection
.
注意:第三个语句有效,因为Illuminate\Support\Collection
还有一个take
函数.
归档时间: |
|
查看次数: |
381 次 |
最近记录: |