Support the ongoing development of Laravel.io →
Database Eloquent Architecture
Last updated 2 years ago.
0

IMMO the first way is the way to go. You want to work with that item so grab it and do something with it. In the second case what if you want to display anything else than its bought attribute.

Last updated 2 years ago.
0

Well I can still work with the item using the second example, the same way as with the first. If the item is empty, in this case, then the test isn't passed so we do nothing with the item anyway :)

Last updated 2 years ago.
0

Quick note:

Model::find($id);
// is exactly the same as:
Model::where('id','=',$id)->first();

Above is true as long as $id is single id, not an array of ids (which can be done too)

Last updated 2 years ago.
0
Solution

Mandor53 said:

Well I can still work with the item using the second example, the same way as with the first. If the item is empty, in this case, then the test isn't passed so we do nothing with the item anyway :)

Yes but if someday you decide to do anything else than check the bought attribute, you have to modify your query. I feel like the second exemple is too restrictive.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Mandor53 mandor53 Joined 1 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.