Laravel Eloquent - get last insert of related model

If the relationship between Terminal and Terminal rent is hasMany you can do something like:

$lastRented = $lastRent->terminalRent->last();

Ensure you have the last rented via dd($lastRented);

Let me know how you get on

Edit: If this gives you the incorrect instance of terminalRent try first(); I can't remember how Eloquent orders eagerlaoded relationships by default.


Try This Code

$lastRent =  Terminal::with(['terminalRent' => function ($query) { 
                        $query->orderBy('id', 'desc')->first();
                }]);