vendredi 27 septembre 2019

Get hidden attribute of a model specified using Model::with()

In a controller, I use this code to get all Text objects and their associated authors

return Text::with('author')->get();

This is part of a backend only available to admins, and I need them to be able to access the author's name field. But in the author's model, I set protected $hidden = ['name']; when I programmed another part of my app that's for standard users.

Is there a way to use with, but get some hidden attribute? Or the other way round, to declare some attribute as hidden temporarily when using with?

Please note this is question is about the use of with in combination with hidden attributes. I'm not looking for something like $authors = $authors->makeVisible(['name']); (which is explained here).



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2nIYzvk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire