user2317976 introduced a great static way to select columns of related tables.
Here is a dynamic trick I found so that you can get whatever you want when using the model:
return Response::eloquent(Theme::with(array('user' => function ($q) { $q->addSelect(array('id','username')) }))->get();
I just found that this trick also works well with load (). It is very convenient.
$queriedTheme->load(array('user'=>function($q){$q->addSelect(..)});
Make sure you also include the key of the target table, otherwise it will not be able to find it.
KinoP Oct 22 '14 at 2:52 2014-10-22 02:52
source share