Fzoltan87
Fzoltan87
FFilament
Created by Fzoltan87 on 12/12/2023 in #❓┊help
Dynamic fields based on a select option with Tabs
My problem is as follows: On the create page, when I select a product type on the "Default TAB" tab, the form associated with that product type should load on the "Data TAB" tab. This works on the create page, the data is entered insert the database. However, when I open the editing page, even though the product type is loaded back from the database, the "Data TAB" on the second tab remains empty – the corresponding form is not loaded. In fact, nothing is loaded. What could be the solution? Tab::make('Default TAB') ->schema([ Select::make('type_id')->label(__('Product Type'))->required()->searchable() ->options(\App\Models\List\ProductType::orderBy('id', 'asc')->pluck('name', 'id')->toArray()) ->live(), ])->columns(4), Tab::make('Data TAB') ->schema(fn (Get $get): array => match ($get('type_id')) { default => [], '1' => [ProductDataContactLensForm::make('cldata')->columns(4)], '3' => [ProductDataSunGlassForm::make('sgdata')->columns(4)], '5' => [ProductDataSpectacleFrameForm::make('sfdata')->columns(4)], }),
2 replies
FFilament
Created by Fzoltan87 on 11/27/2023 in #❓┊help
Custom page with one edit form
I have created a custom page with a modification form. The form is working properly (The data is modified in the database). My only question is, is the implementation of the data saving and query function this way correct? Thanks for the help. PageSettings.php <?php namespace App\Filament\Pages; use App\Services\AppointmentService; use App\Models\Setting; use Filament\Forms; use Filament\Forms\Form; use Filament\Pages\Page; use Filament\Actions\Action; use Filament\Forms\Contracts\HasForms; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Support\Exceptions\Halt; use Filament\Notifications\Notification; use Illuminate\Database\Eloquent\Model; class PageSettings extends Page implements HasForms { use InteractsWithForms; protected static ?string $navigationIcon = 'heroicon-o-document-text'; protected static string $view = 'filament.pages.page-settings'; public ?array $data = []; public function mount(): void { $this->form->fill($this->getSetting()); } public function form(Form $form): Form { return $form ->schema([]) ->statePath('data'); } protected function getFormActions() { ... } //data saving public function save(): void { try { $data = $this->form->getState(); $this->handleRecordUpdate($data); } catch (Halt $exception) { return; } Notification::make() ->success() ->title(__('Successfully data updated')) ->send(); } // data query to mount() function protected function getSetting(): array { $setting = Setting::first(); return $setting->attributesToArray(); } // data query from database protected function handleRecordUpdate(array $data): Model { $record = Setting::find(1); $record->update($data); return $record; } }
2 replies