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

APPLE199's avatar

What is the difference between exists() and exists?

Consider this:

$user = User::first() ?: new GuestUser();

When I do $user->exists() if the user does not exist, it returns false. Same as if I do $user->exists.

What is the difference between the two?

And also, in my production server, $user->exists() always returns true even though if it does not exist. Why do you think it may happen? $user->exists is the right value. Thanks.

0 likes
1 reply
RoboRobok's avatar
Level 7

The difference is huge.

$user->exists contains true if the model is the real model taken from the database. For example, if you create $user = new User and set some properties to it, $user->exists will contain false, as long as you don't do $user->save(). Once it's saved or obtained from database, $model->exists will be true.

On the other hand, $user->exists() is a builder's method. It runs SQL's EXISTS query. If you run $user->exists(), you will generate a query:

select exists(select * from `users`) as `exists`

That will return 1 if any user exists in the database. exists() method feels more natural in Eloquent calls, like:

$thereAreKids = User::where('age', '<', 18)->exists();
40 likes

Please or to participate in this conversation.