0

I have a model User.

There is a defined a hidden property.

protected $hidden = [
        'password', 'remember_token', 
        'user_type', 'balance', 'reputation', 'country', 'region', 'dob', 'street', 'zipPostal'
    ];

Mostly all this fields are should be hidden and it works, but sometimes I need to avoid this restriction and select with this data. How can I do that?

Denys Siebov
  • 198
  • 4
  • 16

1 Answers1

0

I've found a solution in a standart ->makeVisible(['<property_name>']) function. https://laravel.com/docs/5.5/eloquent-serialization#hiding-attributes-from-json

So, it looks like:

$user = Auth::user()->makeVisible(['balance', 'reputation']);

Denys Siebov
  • 198
  • 4
  • 16