%PDF- %PDF-
Direktori : /var/www/html/klinisol/klinisol-api/app/Models/ |
Current File : /var/www/html/klinisol/klinisol-api/app/Models/User.php |
<?php namespace App\Models; use App\Notifications\PasswordResetNotification; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Passport\HasApiTokens; use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable { use HasApiTokens, Notifiable, HasRoles; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'surname', 'email', 'password', 'is_enabled', ]; protected $guarded = [ 'role_id', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = []; public static function getAdminChannels() { $users = self::query() ->whereHas('roles', function ($r) { $r->where('name', Role::ADMIN); }) ->get()->pluck('email'); $channels = collect(); foreach ($users as $user) { $channels->push("user.$user"); } return $channels->toArray(); } public function fullName() { return $this->name . ' ' . $this->surname; } /** * @return |null */ public function getRoleId() { if ($role = $this->roles() ->first()) { return $role->id; } return null; } /** * @return |null */ public function getRoleName() { if ($role = $this->roles() ->first()) { return $role->name; } return null; } /** * @return $this */ public function enable() { $this->is_enabled = true; $this->save(); return $this; } /** * @return $this */ public function disable() { $this->is_enabled = false; $this->save(); return $this; } /** * @param $password * @return $this */ public function updatePassword($password) { $this->password = $password; $this->save(); return $this; } /** * @param $value */ public function setPasswordAttribute($value) { $this->attributes['password'] = bcrypt($value); } public function sendPasswordResetNotificationEmail($token, $department) { $this->notify(new PasswordResetNotification($token, $department)); } }