New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception with not found model (soft deleted) with form and SelectInput with editOptionForm #12495
Comments
@gpibarra Hi! The issue occurs because you are trying to view the author of a deleted post, but the In my opinion, this is not a Filament issue. |
In my opinion, filament should detect this situation (the field value has data, but the model is not loaded, in this case, because it is deleted with soft delete), in the function
does not detect this situation, then advances to filament/packages/forms/src/Components/Select.php Line 1000 in a873b85
I think at some point I should check this, so as not to try to render an 'edit option' if the option is not available... and even. Finally, the edit-option actions at
and create-option at
should have a label so that this text can be changed by translations
|
I agree that this isn't really a problem with Filament, an error is a good thing if the data doesn't make sense (records are related to deleted records), and I can't imagine why an observer cannot be used to remove the bad data there. Feel free to push back with other reasoning and I can reconsider and reopen if appropriate. |
I agree that the data doesn't make sense. The question is whether filament should throw an exception or not, or whether it should hide the edit button in this case |
Having the exception in your error tracker could point you to an actual problem with your app, instead of staying silent about it |
Package
filament/forms
Package Version
v3.2.40
Laravel Version
v11.5.0
Livewire Version
v3.4.11
PHP Version
PHP 8.3.6
Problem description
On a form with a SelectInput field with a
BelongsTo
relationship, usingeditOptionForm
to edit the related record, on an edit page with an existing and related record, fails if the already related model does not exist (at the database level, records are related correctly and the contrains do not fail, but since the related model uses softDelete, the model does not exist in the relationship)Expected behavior
The SelectInput field shows the
id
and not thename
if the relationship model cannot be retrieved, this does not give an exception, but I don't think it is expected behavior. As expected, I think the field should be blank, and the edit option button should not be displayed.Steps to reproduce
# composer create-project laravel/laravel . curl -o filament-issue.zip https://filament-issue.unitedbycode.com/storage/filament-issue.zip unzip filament-issue.zip
Changes in mgrations
database/migrations/2024_04_25_150421_alter_users_table_column_soft_deletes.php
database/migrations/2024_04_25_150500_create_posts_table.php
Changes in models
app/Models/User.php
app/Models/Post.php
Run migrations
Create another user and post
Create resourse
Changes in
app/Filament/Resources/PostResource.php
http://127.0.0.1:8000/posts/1/edit
. This work.Delete user
test@mail
(soft deleted)php artisan tinker --execute="App\Models\User::query()->where('email', 'test@mail')->first()?->delete();"
http://127.0.0.1:8000/posts/1/edit
. This don't workRestore user
test@mail
(soft deleted)php artisan tinker --execute="App\\Models\\User::query()->withTrashed()->where('email', 'test@mail')->first()?->restore();"
http://127.0.0.1:8000/posts/1/edit
. This work.Reproduction repository
https://github.com/gpibarra/filament-issue-form-BelongsToSelect--with-editOptionForm
Relevant log output
No response
The text was updated successfully, but these errors were encountered: