- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
47 lines
1 KiB
PHP
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.");
|
|
}
|
|
});
|
|
}
|
|
}
|