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.
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 :)
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)
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community