Custom setting page with filamentphp
I'm attempting to set up the edit page as the primary view for a filamentphp resource, specifically for managing page settings. These settings will consist of a single data row, and I want to restrict it to only being editable, with no option to create new rows or delete the existing one. Despite my efforts to find a solution, I haven't been able to. I'm open to any pointers, workarounds, or alternative approaches that could help me achieve this. Thanks for your assistance!
18 Replies
Thank you for your question. To get a bit more context, what would be the name of the Model you want the Edit page for? (just trying to get a mental image)
is it just Settings?
Yes it's just Settings
Ok, so I'll assume the model class name is Settings? When you say there's only a single data row, does that mean that the settings table (associated to the Settings model) only has a single record?
Yes, it will contain content like website name, contact, address etc, so there can't be multiple rows for it
Ok. It sounds like you don't really need a whole Resource class to edit the Settings. Sounds more like you just need a custom Page.
when you create a custom page with
php artisan make:filament-page Settings
, it will create a navigation item for youYes can work with page plus livewire component
The new page itself is a full page livewiere component. And, you can implement the HasForms contract to use Filament's form builder inside this page.
I managed to make it up to here, but the problem came again filling the form with the database data, I did use fill() method on the form but it prevents me from editing the data since it keeps refreshing with the database data once I start typing
Interesting...
Would you mind sharing the code for the Page class you created? you can use three back ticks and then php to share code
I think in this case, it would be better to fill the form in the mount() method of the Page class instead of calling the ->fill() method directly in the form schema
i did try, but was getting some that I can't use before instantiating the form,
That's strange. This is how the official documentation recommends adding a form to a component. For our purposes, we can replace Component with Page
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#adding-the-form
I have been referencing the docs trying to solve it but the problem has persisted, maybe I should try updating the filamentphp for now
That's a good idea.
Updating filamentphp and using this solved the problem