The latestOfMany() method lets you use a 'hasMany' relation as a 'hasOne' relation, returning the latest record

The latestOfMany() method lets you use a 'hasMany' relation as a 'hasOne' relation, returning the latest record

🔥 In an Eloquent model can define a relation that will get the newest (or oldest) item of another relation. Very nice!

📘 Docs: https://laravel.com/docs/8.x/eloquent-relationships#has-one-of-many

#laravel #php

We're writing a book, you can get it for free here.