1

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.

2
  • 1
    User::find(2) will return user with primary key 2. check here, why are you useing first() Commented Nov 4, 2014 at 12:44
  • I think ->first() is somehow, working against you. Have you tried without? Commented Nov 4, 2014 at 12:45

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.