fix bugs and deletes unnecessary files
This commit is contained in:
+42
-6
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\MainSectionResource\RelationManagers;
|
||||
|
||||
use App\Models\SubSection;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
@@ -24,12 +25,18 @@ class SubSectionsRelationManager extends RelationManager
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('title')->label('Название подраздела')->required()
|
||||
Forms\Components\TextInput::make('title')
|
||||
->label('Название подраздела')
|
||||
->required()
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(function (string $operation, string $state, Forms\Set $set) {
|
||||
$set('slug', Str::slug($state));
|
||||
}),
|
||||
TextInput::make('slug')->label('Slug')->unique(ignoreRecord: true)->readOnly()->required(),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->unique(ignoreRecord: true)
|
||||
->readOnly()
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -47,16 +54,45 @@ class SubSectionsRelationManager extends RelationManager
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
Tables\Actions\AssociateAction::make()
|
||||
Tables\Actions\Action::make('associate')
|
||||
->label('Прикрепить подраздел')
|
||||
->color('success')
|
||||
->form([
|
||||
Forms\Components\Select::make('recordId')
|
||||
->label('Подраздел')
|
||||
->searchable()
|
||||
->preload()
|
||||
->options(SubSection::whereNull('main_section_id')->pluck('title', 'id'))
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$subSection = SubSection::find($data['recordId']);
|
||||
$subSection->mainSection()->associate($this->getOwnerRecord());
|
||||
$subSection->save();
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
Tables\Actions\Action::make('detach')
|
||||
->label('Открепить')
|
||||
->color('danger') // Красный цвет
|
||||
->icon('heroicon-o-x-mark')
|
||||
->action(function ($record) {
|
||||
$record->mainSection()->dissociate();
|
||||
$record->save();
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DetachBulkAction::make(),
|
||||
Tables\Actions\Action::make('bulkDetach')
|
||||
->label('Открепить выбранные')
|
||||
->action(function ($records) {
|
||||
$records->each(function ($record) {
|
||||
$record->mainSection()->dissociate();
|
||||
$record->save();
|
||||
});
|
||||
}),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user