May 18, 2022
I created an admin panel using Laravel Filament and used the unique()
modifier on an input, but I was unable to save subsequent changes after creation because the resource wasn’t unique to itself (another resource with the same value already existed, which was itself).
Filament’s unique()
method comes with a way of ignoring certain models, which we can use to ignore itself.
That way, we’ll be able to save changes to a model without getting an error saying that a field is not unique.
Update your usage of the unique()
modifier to be like this:
Forms\Components\TextInput::make('slug')
- ->unique();
+ ->unique(ignorable: fn ($record) => $record);
Now, the currently-being-edited model will be ignored when checking for uniqueness.
Tufts Meal Plan Wrapped
Mar 2, 2024
Building an e-ink picture frame that displays an iCloud photo album
Jan 9, 2024
2023 in review
Jan 5, 2024
Subscribe to my newsletter for a monthly round-up of new blog posts and projects I’m working on!