adding multiple categories in ProductResource error

When i add multiple categories in the ProductResource, it saves them. But on the edit page the categories are removed. this is the code in the product model:
public function category(): BelongsToMany
{
return $this->belongsToMany(Category::class);
}
public function category(): BelongsToMany
{
return $this->belongsToMany(Category::class);
}
in the category model i have added this:
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class);
}
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class);
}
in the ProductResource this code:
Forms\Components\BelongsToManyMultiSelect::make(name: 'category_id')
->preload()
->multiple()
->relationship(name: 'category', titleAttribute: 'name') // Display the category names
->required()
->searchable(),
Forms\Components\BelongsToManyMultiSelect::make(name: 'category_id')
->preload()
->multiple()
->relationship(name: 'category', titleAttribute: 'name') // Display the category names
->required()
->searchable(),
how can i fix this? ps how can i add snippets of codes here?
No description
8 Replies
raheel3031
raheel30312w ago
i tried multiple ways but it seems not working
jigsaw
jigsaw2w ago
could you send the code?
raheel3031
raheel30312w ago
How? It is in the first post
jigsaw
jigsaw2w ago
which filamentphp version are you using? have you tried these two? there is no component called BelongsToManySelect
raheel3031
raheel30312w ago
filament 3 i have changed to select no but the problem remains the examples you gave i have tried
jigsaw
jigsaw2w ago
could you provide a demo repo?
raheel3031
raheel30312w ago
how?
Want results from more Discord servers?
Add your server