Files
test_test/app/Models/Role.php
2026-04-06 18:44:02 +05:00

33 lines
697 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Role extends Model
{
public $timestamps = false;
protected $fillable = [
'name',
'slug',
'description',
];
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class)->withTimestamps();
}
public function permissions(): BelongsToMany
{
return $this->belongsToMany(Permission::class)->withTimestamps();
}
public function hasPermission(string $permissionSlug): bool
{
return $this->permissions()->where('slug', $permissionSlug)->exists();
}
}