Edit File: Role.php
<?php namespace App\Models; use App\Traits\ModelTrait; use Illuminate\Database\Eloquent\Relations\HasMany; use Spatie\Translatable\HasTranslations; use Illuminate\Database\Eloquent\SoftDeletes; class Role extends BaseModel { use SoftDeletes; use HasTranslations; use ModelTrait; protected $fillable = ['name']; public $translatable = ['name']; /** * Get all of the permissions for the Role * * @return HasMany */ public function permissions(): HasMany { return $this->hasMany(Permission::class); } public function admins(): HasMany { return $this->hasMany(Admin::class); } public static function boot() { parent::boot(); static::deleting(function ($role) { if ($role->admins()->exists()) { throw new \Exception(__('admin.this_role_has_admins_cannot_be_deleted')); } }); } }
Back to File Manager