Skip to content

Conversation

@martiros
Copy link
Contributor

@martiros martiros commented Mar 2, 2015

Problem
We have many cases when hidden/visible options depend on user privileges.
For example the API that returns other user info must return also user email only if the user is logged in.

Solution
Allow define hidden/visible options more dynamically by overriding getHidden or getVisible methods.

Example

class User extends Illuminate\Database\Eloquent\Model {

    protected $table = 'user';

    public function getHidden()
    {
          if (Auth::check()) {
              return [];
          }
          return ['email'];
    }
}

So by default we will keep _protected $hidden = [];_ option, but also allow override getHidden method to define this options more dynamically.

What do you think, can be this part of the framework ?

@JosephSilber
Copy link
Contributor

The $hidden property is more of a quick patch. It's not meant to be a fully functioning solution.

If you need real logic in there you should ideally be using a presenter or a transformer.

taylorotwell added a commit that referenced this pull request Mar 3, 2015
[5.1] [Proposal] Allow define hidden/visible options dynamically.
@taylorotwell taylorotwell merged commit 0a0c2c2 into laravel:master Mar 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants