I would like to prevent some users from accessing certain database columns based on role management. I can use setAppends() to change a models appends for accessors/mutators. However, I haven't found a way to change this on the fly when using eager loading.
The following example will enable accessors/mutators for the User model. How do I also set the appends for the Accounts model which I'm eager loading? Is there a better way to go about this?
$data = User::with('accounts')->get();
$data->each(function($item){
$item->setAppends(array('accountId', 'createdAt', 'username', 'firstName', 'lastName'));
});
return $data->toArray();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community