You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a problem. I have a one to many relation between my to models 'Vendor' and 'Product'.
Vendor.php:
... public function products() { return $this->hasMany(Product::class, 'vendor_id', 'id'); } ...
Product.php: ... public function vendor() { return $this->belongsTo(Vendor::class); } ...
The migrations looks like this:
xxx_create_product_table.php: ... $table->unsignedBigInteger('vendor_id')->nullable(); $table->foreign('vendor_id')->references('id')->on('vendor'); ...
As you can easily see the relationship between a vendor and its many products is stored in the product table using the field vendor_id.
However, I get an error, when I try to select the products using the edit screen.
In the fields function in my VendorResource.php I have the following defined: Relation::make('products.') ->fromModel(Product::class, 'title') ->multiple() ->title('Produkte'),
When trying to save changes to the field, I get the following error: Column not found: 1054 Unknown column 'products' in 'field list' (SQL: update 'vendor' set 'products' = ["6"] ...
What am I missing here? The relation should only be saved in the product's column.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I have a problem. I have a one to many relation between my to models 'Vendor' and 'Product'.
Vendor.php:
... public function products() { return $this->hasMany(Product::class, 'vendor_id', 'id'); } ...
Product.php:
... public function vendor() { return $this->belongsTo(Vendor::class); } ...
The migrations looks like this:
xxx_create_product_table.php:
... $table->unsignedBigInteger('vendor_id')->nullable(); $table->foreign('vendor_id')->references('id')->on('vendor'); ...
As you can easily see the relationship between a vendor and its many products is stored in the product table using the field vendor_id.
However, I get an error, when I try to select the products using the edit screen.
In the fields function in my VendorResource.php I have the following defined:
Relation::make('products.') ->fromModel(Product::class, 'title') ->multiple() ->title('Produkte'),
When trying to save changes to the field, I get the following error:
Column not found: 1054 Unknown column 'products' in 'field list' (SQL: update 'vendor' set 'products' = ["6"] ...
What am I missing here? The relation should only be saved in the product's column.
Thank you very much for your help!
Best regards,
Patrick
Beta Was this translation helpful? Give feedback.
All reactions