samedi 28 mai 2016

How to eager-load models with only some of their fields?

I have two models: Question and Answer. A question has-many answers. To eager-load a question's answers, one must write it like this:

$question->load('answers');

However, all of the answers' properties are loaded this way. The following code, while illustrating what I want to achieve, does not work:

$quesiton->load('answers')->select('id', 'body')

So, how can I eager-load questions' answers with only their respective id, and body properties?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire