/home/techb158/immovalet.com/platform/core/acl/src/Models
Edit: /home/techb158/immovalet.com/platform/core/acl/src/Models/User.php (5667B)
'json',
];
/**
* Always capitalize the first name when we retrieve it
* @param string $value
* @return string
*/
public function getFirstNameAttribute($value)
{
return ucfirst($value);
}
/**
* Always capitalize the last name when we retrieve it
* @param string $value
* @return string
*/
public function getLastNameAttribute($value)
{
return ucfirst($value);
}
/**
* @return string
* @deprecated since v5.15
*/
public function getFullName()
{
return $this->name;
}
/**
* @return string
*/
public function getNameAttribute()
{
return ucfirst($this->first_name) . ' ' . ucfirst($this->last_name);
}
/**
* @return BelongsTo
*/
public function avatar()
{
return $this->belongsTo(MediaFile::class)->withDefault();
}
/**
* @return UrlGenerator|string
*/
public function getAvatarUrlAttribute()
{
if ($this->avatar->url) {
return RvMedia::url($this->avatar->url);
}
try {
return (new Avatar)->create($this->name)->toBase64();
} catch (Exception $exception) {
return RvMedia::getDefaultImage();
}
}
/**
* @param string $value
* @return array
*/
public function getPermissionsAttribute($value)
{
try {
return json_decode($value, true) ?: [];
} catch (Exception $exception) {
return [];
}
}
/**
* Set mutator for the "permissions" attribute.
*
* @param array $permissions
* @return void
*/
public function setPermissionsAttribute(array $permissions)
{
$this->attributes['permissions'] = $permissions ? json_encode($permissions) : '';
}
/**
* @return BelongsToMany
*/
public function roles()
{
return $this->belongsToMany(Role::class, 'role_users', 'user_id', 'role_id')->withTimestamps();
}
/**
* @return boolean
*/
public function isSuperUser()
{
return $this->super_user || $this->hasAccess(ACL_ROLE_SUPER_USER);
}
/**
* @param string $permission
* @return boolean
*/
public function hasPermission($permission)
{
if ($this->isSuperUser()) {
return true;
}
return $this->hasAccess($permission);
}
/**
* @param array $permissions
* @return bool
*/
public function hasAnyPermission(array $permissions)
{
if ($this->isSuperUser()) {
return true;
}
return $this->hasAnyAccess($permissions);
}
/**
* @return array
*/
public function authorAttributes()
{
return [
'name' => $this->name,
'email' => $this->email,
'avatar' => $this->avatar_url,
];
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
/**
* Returns the activations relationship.
*
* @return HasMany
*/
public function activations()
{
return $this->hasMany(Activation::class, 'user_id');
}
/**
* {@inheritDoc}
*/
public function inRole($role)
{
$roleId = null;
if ($role instanceof Role) {
$roleId = $role->getKey();
}
foreach ($this->roles as $instance) {
/**
* @var Role $instance
*/
if ($role instanceof Role) {
if ($instance->getKey() === $roleId) {
return true;
}
} elseif ($instance->getKey() == $role || $instance->slug == $role) {
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*/
public function delete()
{
if ($this->exists) {
$this->activations()->delete();
$this->roles()->detach();
}
return parent::delete();
}
}