*/ protected $fillable = [ 'username', 'first_name', 'last_name', 'email', 'phone', 'password', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', 'permissions' ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; // protected $hidden = [ // 'permissions' // ]; /** * The attributes to append. * * @var string[] */ protected $appends = [ 'permissions' ]; // public function getPermissionsAttribute() { // return $this->permissions()->pluck('permission')->toArray(); // } /** * Get the list of files of the user * * @return HasMany */ public function permissions() { return $this->hasMany(Permission::class); } /** * Get the permission attribute * * @return array */ public function getPermissionsAttribute() { return $this->permissions()->pluck('permission')->toArray(); } /** * Test if user has permission * * @param string $permission Permission to test. * @return boolean */ public function hasPermission(string $permission) { return ($this->permissions()->where('permission', $permission)->first() !== null); } /** * Get the list of files of the user * * @return HasMany */ public function media() { return $this->hasMany(Media::class); } /** * Get the list of files of the user * * @return HasMany */ public function posts() { return $this->hasMany(Post::class); } /** * Get associated user codes * * @return HasMany */ public function codes() { return $this->hasMany(UserCode::class); } /** * Get the list of logins of the user * * @return HasMany */ public function logins() { return $this->hasMany(UserLogins::class); } }