Added the support for generating docs from template doc
This commit is contained in:
@@ -16,6 +16,7 @@ class User extends Authenticatable
|
||||
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory;
|
||||
|
||||
use HasProfilePhoto;
|
||||
use Notifiable;
|
||||
use TwoFactorAuthenticatable;
|
||||
@@ -64,4 +65,36 @@ protected function casts(): array
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Roles relationship.
|
||||
*/
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class)
|
||||
->withTimestamps()
|
||||
->select('roles.id', 'roles.name', 'roles.slug');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a flattened collection of permissions via roles.
|
||||
*/
|
||||
public function permissions()
|
||||
{
|
||||
return $this->roles()->with('permissions')->get()->pluck('permissions')->flatten()->unique('id');
|
||||
}
|
||||
|
||||
public function hasRole(string|array $roles): bool
|
||||
{
|
||||
$roles = (array) $roles;
|
||||
|
||||
return $this->roles->pluck('slug')->intersect($roles)->isNotEmpty();
|
||||
}
|
||||
|
||||
public function hasPermission(string|array $permissions): bool
|
||||
{
|
||||
$permissions = (array) $permissions;
|
||||
|
||||
return $this->permissions()->pluck('slug')->intersect($permissions)->isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user