Edit only single record with custom page

hi! im newbie in filament and php(laravel), so my question is next: can you explain to me please how i can do edit page like there (https://laraveldaily.com/post/filament-edit-only-single-record-custom-page) but with filament 2.x on our project we use exactly it. for now i created a custom page via command(php artisan make:filament-page EditNotificationBoard) and its content is: <?php namespace App\Filament\Pages; use Filament\Forms\ComponentContainer; use Filament\Forms\Components\TextInput; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Pages\Page; use Filament\Resources\Form; /** * @property Form $form */ class EditNotificationBoard extends Page { use InteractsWithForms; public ?array $data = []; protected static ?string $navigationIcon = 'heroicon-o-document-text'; protected static string $view = 'filament.pages.edit-notification-board'; public function mount(): void { $this->form->fill(); } public function form(Form $form): Form { return $form ->schema([ TextInput::make('message') ->required(), ]); } } the next is my blade.php file and its content is: <x-filament::page> <x-filament::form> {{ $this->form }} </x-filament::form> </x-filament::page> so, after all of that, i cant see my form on the page(looktat the screen) Please, help me!!! and my second question is: could you show me how i can store data as json file on the disk(localy)? Thanks in advance
No description
22 Replies
черешня(вишня)💙💛
Thanks in advance!
черешня(вишня)💙💛
@awcodes thanks a lot! could you please help me with my second question? i really cant find any info about it. is it possible to store data localy as json file?
S. Mert ÖZTÜRK
in your mount; public function mount(): void { $arr = json_decode($json, true); $this->form->fill($arr); } and when you save you can modify your save function
черешня(вишня)💙💛
@S. Mert ÖZTÜRK thank you! i got you. so could you please tell, did i do it right? code snippet: <?php namespace App\Filament\Pages; use Filament\Forms\Components\TextInput; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Pages\Page; class EditNotificationBoar extends Page implements HasForms { use InteractsWithForms; public $json = ''; protected static ?string $navigationIcon = 'heroicon-o-document-text'; protected static string $view = 'filament.pages.edit-notification-boar'; public function mount(): void { $arr = json_decode($this->json, true); $this->form->fill($arr); } protected function getFormSchema(): array { return [ TextInput::make('message') ->required() ->maxLength(255) ->label(__('labels.notification_board.message')) ]; } public function edit(): void { $data = $this->form->getState(); $this->json = json_encode($data); $filePath = storage_path('app/public/data.json'); file_put_contents($filePath, $this->json); } } and i would really appriciate it if you coudl help me to use this method to save data from form here " code snippet: <x-filament::page> <x-filament::form submit="edit"> {{ $this->form }} <x-filament::button type="submit">Зберегти</x-filament::button> </x-filament::form> </x-filament::page>
черешня(вишня)💙💛
for now, it does some request, but nothing saved
No description
S. Mert ÖZTÜRK
can you make dd($this->form->getState()) on edit function and please check your storage path for any creation file
S. Mert ÖZTÜRK
no not assign, edit function first lane dd() direct and click save button, look screen what are come public function edit() { dd($this->form->getState()); ..... other codes here not need remove }
черешня(вишня)💙💛
unfortunately nothing changed i check my storage path twice and didnt find anything
No description
No description
черешня(вишня)💙💛
must the public folder already exist in the app folder? because i dont have the first one
S. Mert ÖZTÜRK
now click your save button, you need to see your form post on screen
черешня(вишня)💙💛
did you mean this?
No description
No description
No description
S. Mert ÖZTÜRK
no, your button orange color. click it
черешня(вишня)💙💛
i clicked. 2nd and 3rd screens that what i got
черешня(вишня)💙💛
i can cick one more time
No description
No description
S. Mert ÖZTÜRK
in your view > form tag change this wire:submit="edit" <x-filament::form wire:submit="edit"> and try again
черешня(вишня)💙💛
okay, let me a min
черешня(вишня)💙💛
so i got it but it shows up for a few seconds
No description
mar5hall
mar5hall9mo ago
I wrote to you in a private message. If it is relevant, I can help.
S. Mert ÖZTÜRK
okay we get form correct. So the error is on creating to json file. Storage::disk('public')->put('data.json', json_encode($data)); you can try this
черешня(вишня)💙💛
thanks every one🤗 issue is solved✅ . for other who has same problem as me, i'll load code to github later
Want results from more Discord servers?
Add your server
More Posts