mercredi 7 mars 2018

Avoid query to check if relation exists in Laravel

In Laravel I've 2 model Man and Car, and the Car model has a foreign key man_id.

Now I would to check if a Car as an owner, so I can do
if($car->man != null)

I could also do:
if($car->man_id != null)
but I don't like this solution...

But in this way Laravel do a query to check if Man exists, is there a way to avoid this useless query?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2I9SkXk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire