[2.x] [Filament] Update deprecated getFormSchema method to use form() override (#354)

This commit is contained in:
Rasel Islam Rafi
2024-11-29 02:13:10 +06:00
committed by GitHub
parent acdbfa70f5
commit d4ec4c66ed
30 changed files with 327 additions and 284 deletions

View File

@ -9,6 +9,7 @@
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Widgets\Widget;
@ -27,24 +28,25 @@ public function mount(Project $project): void
$this->project = $project;
}
public function getFormSchema(): array
public function form(Form $form): Form
{
return [
Section::make()
->heading('Add User')
->schema([
Select::make('user')
->name('user')
->options(fn () => User::query()->pluck('name', 'id'))
->searchable()
->rules(\App\Actions\Projects\AddUser::rules($this->project)['user']),
])
->footerActions([
Action::make('add')
->label('Add')
->action(fn () => $this->submit()),
]),
];
return $form
->schema([
Section::make()
->heading('Add User')
->schema([
Select::make('user')
->name('user')
->options(fn () => User::query()->pluck('name', 'id'))
->searchable()
->rules(\App\Actions\Projects\AddUser::rules($this->project)['user']),
])
->footerActions([
Action::make('add')
->label('Add')
->action(fn () => $this->submit()),
]),
]);
}
public function submit(): void

View File

@ -36,18 +36,23 @@ protected function getTableColumns(): array
];
}
public function getTable(): Table
public function table(Table $table): Table
{
return $this->table->actions([
Tables\Actions\DeleteAction::make()
->label('Remove')
->modalHeading('Remove user from project')
->visible(function ($record) {
return $this->authorize('update', $this->project)->allowed() && $record->id !== auth()->id();
})
->using(function ($record) {
$this->project->users()->detach($record);
}),
])->paginated(false);
return $table
->heading(null)
->query($this->getTableQuery())
->columns($this->getTableColumns())
->actions([
Tables\Actions\DeleteAction::make()
->label('Remove')
->modalHeading('Remove user from project')
->visible(function ($record) {
return $this->authorize('update', $this->project)->allowed() && $record->id !== auth()->id();
})
->using(function ($record) {
$this->project->users()->detach($record);
}),
])
->paginated(false);
}
}

View File

@ -19,8 +19,6 @@ protected function getTableQuery(): Builder
return Project::query();
}
protected static ?string $heading = '';
protected function getTableColumns(): array
{
return [
@ -35,9 +33,12 @@ protected function getTableColumns(): array
];
}
public function getTable(): Table
public function table(Table $table): Table
{
return $this->table
return $table
->heading(null)
->query($this->getTableQuery())
->columns($this->getTableColumns())
->recordUrl(fn (Project $record) => Settings::getUrl(['project' => $record]))
->actions([
Action::make('settings')

View File

@ -8,6 +8,7 @@
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Widgets\Widget;
@ -27,24 +28,25 @@ public function mount(Project $project): void
$this->name = $project->name;
}
public function getFormSchema(): array
public function form(Form $form): Form
{
return [
Section::make()
->heading('Project Information')
->schema([
TextInput::make('name')
->name('name')
->label('Name')
->rules(\App\Actions\Projects\UpdateProject::rules($this->project)['name'])
->placeholder('Enter the project name'),
])
->footerActions([
Action::make('save')
->label('Save')
->action(fn () => $this->submit()),
]),
];
return $form
->schema([
Section::make()
->heading('Project Information')
->schema([
TextInput::make('name')
->name('name')
->label('Name')
->rules(\App\Actions\Projects\UpdateProject::rules($this->project)['name'])
->placeholder('Enter the project name'),
])
->footerActions([
Action::make('save')
->label('Save')
->action(fn () => $this->submit()),
]),
]);
}
public function submit(): void