Ldaprecord-laravel: Make it possible to hide some attributes for serialization

Created on 11 Apr 2020  Â·  5Comments  Â·  Source: DirectoryTree/LdapRecord-Laravel

Similar to the possibility which exists with Eloquent models, I think it should be possible to hide some attributes for serialization purposes. For example, I currently serialize models for logging purposes and don't really want userPassword attribute to be included.

Is this possible?

enhancement

All 5 comments

Hi @mgiritli,

You’re right — this feature isn’t built in right now, you’ll have to do it manually. Though it should definitely be included.

Give me a day or two and I’ll have this patched in, thanks for letting me know!

🎉 All done. You can now add $visible and $hidden properties to your models, or use addHidden() / makeHidden() methods on a model instance:

Via Properties:

class User extends Model
{
    protected $hidden = ['userPassword'];
}

Via Methods:

$user = User::findByAnr('steve');

$user->addHidden('userPassword');
// Or:
$user->makeHidden('userPassword');

// 'userPassword' will be removed from the encoded array.
json_encode($user);

A new release will be out in a couple hours :smile:

This has now been released in v1.4.0.

Thanks so much, Steve :-)

Glad to help @mgiritli! Please feel free to drop in anytime you have any suggestions :smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephancasas picture stephancasas  Â·  6Comments

ellisonpatterson picture ellisonpatterson  Â·  9Comments

brinkonaut picture brinkonaut  Â·  6Comments

aanderse picture aanderse  Â·  3Comments

jagDanJu picture jagDanJu  Â·  8Comments