mercredi 18 avril 2018

Laravel retrieving single related attribute

I have a laravel app that allows users to post posts. Each post has a price (stored as an integer), and belongs to a university, which in turn belongs to a country, which has a currency.

Every-time I retrieve the posts, I want to return the currency as well. I could do with('university.country') but that would return all the details for both the university and country.

I could add a getCurrencyAttribute and define the logic there, but that seems not what mutators are for.

What's the best way to get a single related field, every-time?

Full code on GitHub.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire