jeudi 28 février 2019

Eloquent Get Models based on fields in related tables

I have multiple Models related to my User model(eg: profiles, addresses, orders,...etc)

I want to get all the users that were updated in the past 24 hours, based on the update_at field in each of the related tables accordingly.

I have found the following if u have one related table, but in my case I have more than 3 tables that I need to check:

$users = User::with('orders')
            ->where('updated_at', $valueA)
            ->whereHas('orders', function($query)
                {
                    $query->where('updated_at', $valueB);
                })->get();

I hope someone can help me to know how to apply this for multiple where clauses n=on multiple related tables.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire