Laravel很多人,如何在枢轴表中插入/获取数据?
在Laravel 9中,我实施了许多与许多关系。
我有三个表,<代码> shop ,product
和product_shop
表。
每个商店都可以具有每个产品的号码
。 并且每种产品都可以存在于多家商店中。
问题是如何在product_shop
表中插入/获取号码
?
我必须使用什么关系语法?
product_shop表:
$table->unsignedInteger('product_id');
$table->unsignedInteger('shop_id');
$table->unsignedInteger('number');
$table->foreign('product_id')->references('id')->on('products');
$table->foreign('shop_id')->references('id')->on('shops');
谢谢
in laravel 9 I implement many to many relationship.
I have three table, shop
, product
and product_shop
table.
each shop can have number
of every single product.
and each product can exist in multiple shops.
the question is how can I insert/get the number
of product inside the product_shop
table?
what relationship syntax I have to use?
product_shop table :
$table->unsignedInteger('product_id');
$table->unsignedInteger('shop_id');
$table->unsignedInteger('number');
$table->foreign('product_id')->references('id')->on('products');
$table->foreign('shop_id')->references('id')->on('shops');
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
您可以使用
Pivot
。例如,如果您想插入,
You can use
pivot
. For example,And if you want to insert,