NiRR
NiRR

Reputation: 5002

Laravel find() query doesn't bind any data

Using laravel 4.0

This is my call to find:

User::find(2)->first()

And this is the result from getQueryLog():

[query] => select * from `users` limit 1
[bindings] => Array
    (
    )

I expected that it would use a where = ?.

I'm almost certain this worked well until it didn't.

Thanks for the help.

Upvotes: 1

Views: 76

Answers (1)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111839

It's enough to use:

$user = User::find(2);

It will get you User with primary key 2.

You don't need to and cannot use find with first - there's only one User with given primary key so Eloquent automatically get user and you don't need to use first in this case. You could use first if you would like to get user this way:

$user = User::where('id','2')->first();

The above code is equivalent to:

$user = User::find(2);

(assuming id is primary key)

Upvotes: 1

Related Questions