Framework: [5.7] $visible in eloquent not using custom attributes

Created on 15 Oct 2018  路  1Comment  路  Source: laravel/framework

  • Laravel Version: 5.7
  • PHP Version: 7.2

Description:

For example un User model we have that code:

/**
     * The attributes that should be visible in arrays.
     *
     * @var array
     */
    protected $visible = [
        'id',
        'username',
        'verified'
    ];
public function getVerifiedAttribute($value = null)
    {
        return $this->email_verified_at !== null;
    }

in that case (string) request()->user() will show only id/username in json array, verified is not exists and we manually created it.

Most helpful comment

@n0n0n0n0 you should use protected $appends = ['verified'];

>All comments

@n0n0n0n0 you should use protected $appends = ['verified'];

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kerbylav picture kerbylav  路  3Comments

gabriellimo picture gabriellimo  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments