automaticaly assign guard_name
This commit is contained in:
@@ -13,6 +13,12 @@ class Permission extends Model
|
|||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
|
static::creating(function (Permission $permission) {
|
||||||
|
if (!$permission->guard_name) {
|
||||||
|
$permission->guard_name = 'web';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
static::created(function (Permission $permission) {
|
static::created(function (Permission $permission) {
|
||||||
if ($role = Role::where('name', 'superuser')->first()) {
|
if ($role = Role::where('name', 'superuser')->first()) {
|
||||||
$role->permissions()->attach([$permission->id]);
|
$role->permissions()->attach([$permission->id]);
|
||||||
|
|||||||
@@ -6,5 +6,18 @@ use Spatie\Permission\Models\Role as Model;
|
|||||||
|
|
||||||
class Role extends Model
|
class Role extends Model
|
||||||
{
|
{
|
||||||
//
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public static function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
static::bootTraits();
|
||||||
|
|
||||||
|
static::creating(function (Role $role) {
|
||||||
|
if (!$role->guard_name) {
|
||||||
|
$role->guard_name = 'web';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user