I have two entities: Producers and Protocols. Producers has many Protocols.
Problem
Select all producers ordered by their last protocol creation date.
Solution
In order to get this, I tried:
$producers = Producer::join('protocol', 'protocol.producer_id', '=', 'producer.id')
->orderBy('protocol.created_at', 'desc');
But just didn't work as expected mainly because I even limited the last protocol. How can I achieve this using Laravel Eloquent?