Saving Optional Relationship to db does not persist

Edit: This is not solved, only halfway there :(
Hey all,
I've been trying my hand at Laravel and filament for the last couple of weeks and am stuck on something:
I have two entities, Book and BookPoster. Both have their foreign_key value set as nullable (because a book might not have a poster at creation).
The BookResource's form looks as follows:
return $form
            ->schema([
                Forms\Components\TextInput::make('title')->required(),
                Forms\Components\Select::make('book_poster_id')->relationship(name:"poster", titleAttribute: "name")->label("Poster")
                    ->createOptionForm([
                        Forms\Components\TextInput::make('name')->required(),
                        Forms\Components\FileUpload::make('poster_path')->required()
                    ])
            ]);

When selecting a BookPoster from the list, the value does not get persisted in database. Do you know what I might be doing wrong?
Solution
Why do you have a book_id on the book_poster table? Can a poster only post one book?

Honestly I don't know how this would work with laravel or fillament by default. You essentially have 2 different relations here - A poster had a book and a book has a poster but they can be different.

I think you will need to override the default create method if you want to change the book_id on the book_poster table (or use a mutateData... method)
Was this page helpful?