我有一个包含各种产品的产品页面。用户可以撰写有关产品的评论。
我想通过产品列表ID(product_id),因此当用户添加评论时,产品ID会随评论一起添加到数据库中。
Database one (products): product_id and description
Database two (reviews): product_id, user_id and review
我可以通过$ reviews-> user_id = auth() - > user() - > id传递user_id;我不想硬编码按钮并像那样通过prouct_id,还有其他方法吗?
答案 0 :(得分:0)
通常情况下,我们无需在向控制器发布数据时重新加载页面。因此,根据我的想法,您应该对控制器进行ajax调用,并在此情况下发布您想要的数据,您需要user_id,product_id,review
$.ajax ({
type: "POST",
url: '{{URL::route("route_name")}}',
data: {
'user_id': value,
'product_id': value,
'review': value
},
success(data) {
console.log(data);
}
});
我不确定是否解决了你的问题。只是我的想法。