Using the with
method, I do not see anything near, on the docs, as to what I want to accomplish. Possible?
// bars is a hasMany() association
public function getFoo($id, $fooId)
{
return $this
->where('id', $id)
->where('fooId', $fooId)
->with([
'one',
'two',
'bars' => function($queries) {
foreach ($queries as $key => $query) {
$queries[$key]['extraKey'] = 'extraValue'; // extrakey can be any name I want it to be.
// $query['extraKey'] = "extraValue";
}
}
])
->first();
}
I'm following Vlad's answer how to loop and modify but I'm not seeing extraKey
in the returned data.
Do I have perform this action in the controller? Seems messy if that's the only way. I thought I could so these actions within the model itself.
I expect to see:
foo->bars[0]->extrakey;