user()->can('manage_prices') || auth()->user()->can('admin'); } protected static ?string $navigationIcon = 'heroicon-o-banknotes'; protected static ?string $navigationGroup = 'Pozostałe'; protected static ?string $title = 'Cennik badań'; protected static ?int $navigationSort = 1; protected static string $view = 'filament.pages.custom-edit-page'; public function getMaxContentWidth(): MaxWidth { return MaxWidth::FourExtraLarge; } public ?array $data = []; public function mount(): void { $firstRecord = \App\Models\Price::first(); if ($firstRecord) { $this->data = $firstRecord->toArray(); $this->form->fill($this->data); } } public function form(Form $form): Form { return $form->schema([ Card::make() ->schema([ Select::make('attachment_id') ->label('Powiązany załącznik') ->options(function () { return \App\Models\Attachment::all()->pluck('file_name', 'id'); }) ->nullable() ->default(null) ->searchable() ->preload() ->reactive(), ]), ])->statePath('data'); } public function getFormActions(): array { return [ Action::make('save') ->label('Zapisz') ->action('save'), ]; } public function save(): void { $validatedData = $this->form->getState(); try { $price = \App\Models\Price::first(); $price->fill($validatedData); $price->save(); Notification::make() ->title('Sukces!') ->body('Rekord został zapisany pomyślnie.') ->success() ->send(); } catch (\Exception $e) { Notification::make() ->title('Błąd!') ->body('Wystąpił problem podczas zapisywania rekordu: ' . $e->getMessage()) ->danger() ->send(); } } }