Skip to content
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

Apparent problem when saving BelongsToMany relationship from CreateRecord page using 'Select' form component. #14622

Open
caswd opened this issue Oct 24, 2024 · 2 comments
Labels

Comments

@caswd
Copy link

caswd commented Oct 24, 2024

Package

filament/forms

Package Version

v3.2.121

Laravel Version

v11.9

Livewire Version

No response

PHP Version

PHP 8.3

Problem description

I have a model with a BelongsToMany relationship. It has a standard Filament resource with pages.
The form of this resources includes a Select field where multiple records can be selected for a BelongsToMany relationship. This all works fine on the Edit page, but on the Create page, no relations are created in the pivot table.
The strange thing is that if the field has validation, the validation does work! After that however, the $state is always null and the data is not saved.

Again: Everything works on the Edit page, just not on the Create page.`

Expected behavior

When I create a new record (book in my example) and select two authors in the 'author' Select field, I expect the book to be created, with the two authors linked via the author_books table.

Instead, the author_books table is not touched and the authors field is empty after the page redirects to the Edit page for the newly created book.

Steps to reproduce

  1. Checkout the repo: https://github.com/caswd/replicate-filament-create-with-many-to-many-select-issue
  2. composer install; php artisan migrate; php artisan db:seed; (sorry if I missed anything)
  3. Configure the .env
  4. Go to /example/books/create
  5. Select one or two authors
  6. Save the book.
  7. Observe that the book is saved, but without any authors.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/caswd/replicate-filament-create-with-many-to-many-select-issue

Relevant log output

No response

Donate 💰 to fund this issue

  • You can donate funding to this issue. We receive the money once the issue is completed & confirmed by you.
  • 100% of the funding will be distributed between the Filament core team to run all aspects of the project.
  • Thank you in advance for helping us make maintenance sustainable!
Fund with Polar
@caswd
Copy link
Author

caswd commented Oct 24, 2024

Sidenote: Idk whether this is actually a bug or just a mistake by me. Regardless, I donated via Polar even if it's just a small thank you for the business value that Filament has already provided to my product.

@caswd
Copy link
Author

caswd commented Nov 4, 2024

It looks like the select multiple field also gives problems when not using a relationship and just saving an array to a json field... It works on edit page but not on create; the state is always null when the create form is dehydrated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

1 participant