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."); } }); } }