BF default role slug
This commit is contained in:
parent
4488b7821f
commit
2d35fab83d
|
|
@ -21,6 +21,18 @@ class Role extends Model
|
||||||
parent::__construct($attributes);
|
parent::__construct($attributes);
|
||||||
|
|
||||||
$this->table = config('roles.table_names.roles') ?: parent::getTable();
|
$this->table = config('roles.table_names.roles') ?: parent::getTable();
|
||||||
|
|
||||||
|
static::creating(function ($model) {
|
||||||
|
$baseSlug = str()->slug($model->slug ?: $model->name);
|
||||||
|
$slug = $baseSlug;
|
||||||
|
$suffix = 1;
|
||||||
|
|
||||||
|
while (static::where('slug', $slug)->exists()) {
|
||||||
|
$slug = $baseSlug . '-' . $suffix++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->slug = $slug;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function members()
|
public function members()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue