Changes
This commit is contained in:
@@ -34,21 +34,7 @@ class UserResource extends Resource implements HasShieldPermissions
|
|||||||
Forms\Components\TextInput::make('name')
|
Forms\Components\TextInput::make('name')
|
||||||
->required()
|
->required()
|
||||||
->maxLength(255)
|
->maxLength(255)
|
||||||
->live(onBlur: true)
|
->live(onBlur: true),
|
||||||
->afterStateUpdated(function (string $operation, string|null $state, Forms\Set $set) {
|
|
||||||
$slug = Str::slug($state);
|
|
||||||
$count = 1;
|
|
||||||
$baseSlug = $slug;
|
|
||||||
|
|
||||||
while (User::where('slug', $slug)->exists()) {
|
|
||||||
// Если slug существует, добавляем суффикс
|
|
||||||
$slug = $baseSlug . '-' . $count;
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
$set('slug', $slug);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
TextInput::make('slug')->label('Slug')->unique(ignoreRecord: true)->readOnly()->required(),
|
|
||||||
Forms\Components\TextInput::make('email')
|
Forms\Components\TextInput::make('email')
|
||||||
->email()
|
->email()
|
||||||
->required()
|
->required()
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class CreateUser extends CreateRecord
|
|||||||
|
|
||||||
protected function mutateFormDataBeforeCreate(array $data): array
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
{
|
{
|
||||||
|
$data['slug'] = $this->generateUniqueSlug($data['name']);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class EditUser extends EditRecord
|
|||||||
|
|
||||||
protected function mutateFormDataBeforeSave(array $data): array
|
protected function mutateFormDataBeforeSave(array $data): array
|
||||||
{
|
{
|
||||||
|
$data['slug'] = $this->generateUniqueSlug($data['name']);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +39,7 @@ class EditUser extends EditRecord
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class User extends Authenticatable implements FilamentUser
|
|||||||
'name',
|
'name',
|
||||||
'email',
|
'email',
|
||||||
'password',
|
'password',
|
||||||
|
'slug'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user