filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.09k stars 2.83k forks source link

Relationships within a relationship Repeater aren't saved #9238

Closed olivierguerriat closed 11 months ago

olivierguerriat commented 11 months ago

Package

filament/filament

Package Version

^3.0-stable

Laravel Version

^10.10

Livewire Version

?

PHP Version

8.1

Problem description

When saving an object (recipe) containing a Repeater associated to a relationship (recipe ingredients), itself containing a Select associated to a relationship (ingredients), that last relationship isn't saved even though the other fields within the repeater (quantity) work as expected.

SQLSTATE[HY000]: General error: 1364 Field 'ingredient_id' doesn't have a default value
INSERT INTO `recipe_ingredients` (`quantity`, `recipe_id`, `updated_at`, `created_at`) VALUES (3, 5, 2023-10-21 16:32:17, 2023-10-21 16:32:17)

Expected behavior

I would expect all fields within the repeater to behave as usual, ending up saved in the DB.

Steps to reproduce

Here's the code within RecipeResource that doesn't work as expected (the Select value isn't considered when inserting the "recipe ingredient" in the database).

Repeater::make('recipe_ingredients')
    ->relationship()
    ->schema([
        TextInput::make('quantity')
            ->numeric()
            ->required(),
        Select::make('ingredient_id')
            ->relationship(name: 'ingredient', titleAttribute: 'label')
    ])

To reproduce, go to the panel in a browser, create a recipe with at least one ingredient (create it inline if required) and save it.

Reproduction repository

https://github.com/olivierguerriat/filament-nested-relationships

(my code is in this commit)

Relevant log output

No response

Possibly related issues

danharrin commented 11 months ago

ingredient_id is not fillable

olivierguerriat commented 11 months ago

Thank you very much! I'm sorry I took your time for this.

(I had it fillable at some point in my main project and it didn't help, but I guess I fixed another problem in the meantime and it now works as expected.)