Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MuhammadYasser's avatar

all() vs get() - Laravel Eloquent

which better between these lines? and why?


$activeCustomers = Customer::all()->where('active', 1);


$activeCustomers = Customer::where('active', 1)->get();

0 likes
5 replies
chatty's avatar
$activeCustomers = Customer::where('active', 1)->get(); //query builder
$activeCustomers = Customer::all()->where('active', 1); //Laravel collection

Query builder is always faster

4 likes
milon's avatar

use 1st option, it runs on the Database side.

1 like
AddWebContribution's avatar

User::all() and User::get() will do the exact same thing.

all() is a static method on the Eloquent\Model. All it does is create a new query object and call get() on it. With all(), you cannot modify the query performed at all (except you can choose the columns to select by passing them as parameters).

get() is a method on the Eloquent\Builder object. If you need to modify the query, such as adding a where clause, then you have to use get(). For example, User::where('name', 'David')->get();

6 likes
nomikz's avatar

Shame on me. I've learnt that just now. I thought I could use get and all interchangeably until my code failed.

1 like
nategg's avatar

I learned it months ago, and it still trips me up at least weekly. Too much to keep in the head all the time.

Please or to participate in this conversation.