Cannot create with a select has relation.
I have a two modal.
Modal Brand has:
public function categories()
{
return $this->belongsToMany(Category::class, 'brand_category', 'brand_id', 'category_id');
}
Modal Category has:
public function products():
{
return $this->hasMany(Product::class, 'category_id', 'id');
}
BrandResource has:
Forms\Components\Select::make('category')
->relationship(name: 'categories', titleAttribute: 'name')
->multiple()
->searchable()
->preload()
When i create a brand and choose a option from select.
I have an error: General error: 1364 Field 'id' doesn't have a default value
3 Replies
id
should be auto-incrementing shouldn't it?I used uuid for id
And i dont create a model for brand_category table
Makes sense that
id
is null then. It cannot be auto-filled by the DB. I think you need a model otherwise that column is always empty