dimanche 20 mai 2018

Eager loading the first item from a related table in laravel 5.4

I have two tables 'purchases' and 'accounts_purchase_history'. purchase has many accounts history. So I need to get all the purchases with the latest history. What i have done so far

 $purchases = Purchases::with(['accounts_purchase_historie' => function($query){
            return $query->orderBy('id','DESC')->first();
        }])->orderBy('id','DESC')->where('status','extended')->get();

But this query only gets the first purchase history, How can i solve this?



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

Aucun commentaire:

Enregistrer un commentaire