'datetime', ]; public function roleUser() { return $this->hasOne(RoleUser::class, 'user_id', 'id'); } protected static function boot() { static::creating(function ($model) { if (!$model->id){ $model->id = (string) Str::uuid(); } }); parent::boot(); } public function authorizeRoles($roles) { if ($this->hasAnyRole($roles)) { return true; } abort(403, 'This action is unauthorized.'); } // public function hasAnyRole($roles) // { // if (is_array($roles)) { // foreach ($roles as $role) { // if ($this->hasRole($role)) { // return true; // } // } // } else { // if ($this->hasRole($roles)) { // return true; // } // } // return false; // } // public function hasRole($role) // { // $hasRole = $this->roleUser()->with(["role"=>function($query) use ($role){ // $query->where("name",$role); // }])->first(); // if ($hasRole->role){ // return true; // }else{ // return false; // } // } }