'Can Anyone Tell me the difference between get() and all() in laravel?
$record = Record::all();
$record::where('user_id',1)->get();
Solution 1:[1]
Record::all() and Record::get() are the same thing.
However all() is a static method on the Eloquent\Model. What is does is create a new query object and call get() on the new object. With all() you're unable to modify the performed query.
get() is a method on the Eloquent\Builder object. get() is useful if you need to modify you're query, like adding a where clause for example.
Solution 2:[2]
with all() you cannot modify the query get() you can modify the query such as adding a where to it.
Solution 3:[3]
all() get all data and do get() too,
get() is for when you use where(),findorfail() and... for get the data ,
https://laravel.com/docs/4.2/eloquent
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | geertjanknapen |
| Solution 2 | Color |
| Solution 3 | amir darabi |
