Edit resource page as the page index
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!
25 Replies
custom page would be the solution i guess
Yes it does work, but the problem comes when I am editing the page, am using ->fill() on the form, when I try to edit it refreshes with the data from the database
I don't get it. If it's only for settings shouldn't it work that way? For example you can check how settings page is done here https://github.com/ploi/roadmap/blob/main/app/Filament/Pages/Settings.php
GitHub
roadmap/app/Filament/Pages/Settings.php at main ยท ploi/roadmap
Open source roadmapping software. Contribute to ploi/roadmap development by creating an account on GitHub.
That
fill
should only happen on the mount()
function and not on your form. You are always re-filling the form.Yes, have noticed, now have changed to
But now
```php
public function create(Setting $setting): void
{
$setting->update($this->form->getState());
$setting->save();
//Its just saving new setting row with all the fields to null
}
Upp, you don't need $setting->update(...) and then $setting->save();
Just use the update and it should work ๐
its not updating the row still
Can you try to add:
If that doesn't work, just check what you get from:
Because I used exactly the same approach with:
with the
dd($this->data);
the data is dumped with no issues but $setting->update($this->data);
still does not update the rowdump the $setting variable and see what it returns
maybe it's not correctly auto-loaded ๐
yes, after dumping $setting from the Setting $setting found it was empty so i change to this
๐
but again its not saving ๐ซ
It's not null and you have data? ๐
Ps. By checking
dd($setting)
make sure that it has an ID attached in attrributes
yes its not nulled since the
$this->getSetting();
retrieves the first row in the tableUm... Can you show me your model that is attached to this?
I suspect that you have missed
$fillable
definition there ๐am not using
id
๐ the primary key is set to company_name
i have protected $fillablewell, whatever primary key you are using - if it has it - then it's okay ๐
all the fields you are trying to update are there?
yes
Hmm
Double check that the Data isn't wrapped with anything else and has a correct structure ๐
Or use saving like this:
Then you can dd($setting) before the save and see if it was filled correctly
dd() on getSetting()
check the #attributes and what's inside ๐
clear views, route etc and tried this again and it works