X7ROOT File Manager
Current Path:
/home/gfecatvj/sites/realesbar/platform/core/acl/src/Models
home
/
gfecatvj
/
sites
/
realesbar
/
platform
/
core
/
acl
/
src
/
Models
/
📁
..
📄
Activation.php
(418 B)
📄
Role.php
(1.95 KB)
📄
User.php
(5.29 KB)
📄
UserMeta.php
(1.48 KB)
Editing: User.php
<?php namespace Botble\ACL\Models; use Botble\ACL\Notifications\ResetPasswordNotification; use Botble\ACL\Traits\PermissionTrait; use Botble\Base\Supports\Avatar; use Botble\Media\Models\MediaFile; use Exception; use Illuminate\Contracts\Routing\UrlGenerator; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use RvMedia; class User extends Authenticatable { use PermissionTrait; use Notifiable; /** * {@inheritDoc} */ protected $table = 'users'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'username', 'email', 'first_name', 'last_name', 'password', 'super_user', 'avatar_id', 'permissions', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The date fields for the model.clear * * @var array */ protected $dates = [ 'created_at', 'updated_at', ]; /** * @var array */ protected $casts = [ 'permissions' => '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 */ public function getFullName() { 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() { return $this->avatar->url ? RvMedia::url($this->avatar->url) : (new Avatar)->create($this->getFullName())->toBase64(); } /** * @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->getFullName(), 'email' => $this->email, 'url' => $this->website, '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(); } }
Upload File
Create Folder