cms/app/Models/Role.php
Funky Waddle 37ed997989 feat(cms): initialize Laravel project structure and core CMS files
- Added standard Laravel directory structure and configuration.

- Included Svelte and Tailwind configuration for the admin interface.

- Added core PHPUnit and testing scripts.
2026-04-13 12:48:06 -05:00

47 lines
1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
protected $fillable = ['name', 'slug', 'description', 'is_protected'];
/**
* The permissions that belong to the role.
*/
public function permissions()
{
return $this->belongsToMany(Permission::class);
}
/**
* The users that belong to the role.
*/
public function users()
{
return $this->belongsToMany(User::class);
}
/**
* Boot the model.
*/
protected static function boot()
{
parent::boot();
static::deleting(function ($role) {
if ($role->is_protected) {
throw new \Exception("The protected '{$role->name}' role cannot be deleted.");
}
});
static::updating(function ($role) {
if ($role->is_protected && $role->isDirty('is_protected')) {
throw new \Exception("The protection status of '{$role->name}' cannot be modified.");
}
});
}
}