How to get latestOfMany() from a not directly related Model – Laravel
I have class People extends Model { public function invoices() { return $this->hasMany(Invoice::class)->orderBy('date', 'desc'); } } ... class Invoice extends Model { public function person() { return $this->belongsTo(People::class, 'people_id'); } public function latestInvoice(){ return $this->hasOne(Invoice::class)->latestOfMany(); } } ... class Clerk…