Stefan
Stefan
Explore posts from servers
TLCTuto's Laravel Corner
Created by Stefan on 3/4/2024 in #💡filament
form builder
can anyone help me hoe to think this? thanks!
3 replies
TLCTuto's Laravel Corner
Created by Stefan on 1/11/2024 in #💡filament
attach properties to products - many to many relation
I have ProductResource and I want to associate some Properties to each product. For this I made a PropertiesRelationalManager The PropertyResource is bind of Property model and to the properties table. The properties table have the 2 columns, id and name The property values are stored in the property_values table which have the following columns: id, property_id and value I have a pivot table product_property with the following columns: id, product_id, property_value_id, property_id and quantity I created a PropertiesRelationManager and registered on the ProductResource and it’s form method looks like this: public function form(Form $form): Form { return $form ->schema([ Forms\Components\Select::make('property_id')->label('Properties') ->relationship('properties', 'name') ->options(Property::all()->pluck('name', 'id')) ->live() ->required(), Forms\Components\Select::make('property_value_id')->label('Values') ->relationship('properties.values', 'value') ->options(function (Forms\Get $get) { $property = Property::find($get('property_id')); return $property ? $property->values->pluck('value', 'id') : []; }) ->live() ->required(), Forms\Components\TextInput::make('quantity'), ]); } Now when I want to save, I get Call to a member function associate() on null Any help will be much appreciated!
3 replies