我在用户从会话中删除项目时,从会话中删除项目时遇到问题。让我将问题分为两部分
谢谢
部分vue代码
<div class="card-body" v-for="(list,index) in cart">
<img :src="list.image" width="80">
index:{{index}} {{list.name}}
<button @click="remove(index)">X</button>
</div>
remove(index){
axios.get('/delete',{
params: {
index: index,
}
}).then((response)=>{
//this.cart123.push(product)
});
}
这是从会话中删除项目的方法
public function removeFromSession(Request $request){
$index = $request->index;//index value of item sent from view when user clicks remove item
$request->session()->forget('product.' . $index);
}
数据在会话中的存储方式为
[
{
id: 2,
name: "Marlene Reichert",
description: "Debitis asperiores sed sit assumenda unde quo natus. Consequatur est labore tenetur quae. Eius distinctio ea omnis aspernatur porro earum quae.",
category_id: 3,
price: 76,
image: "http://loremflickr.com/400/300?random=71",
created_at: "2019-07-16 10:12:27",
updated_at: "2019-07-16 10:12:27",
qty: 1
},
{
id: 4,
name: "Bart Kuvalis",
description: "Eaque iure excepturi nisi est dolore sapiente in sequi. Minus odit ab et id consectetur sunt.",
category_id: 9,
price: 162,
image: "http://loremflickr.com/400/300?random=40",
created_at: "2019-07-16 10:12:27",
updated_at: "2019-07-16 10:12:27",
qty: 1
},
{
id: 6,
name: "Kaylin Emard",
description: "Et aperiam omnis nam iure id non fugiat. Excepturi voluptatem ipsam magnam. Esse asperiores ducimus enim et.",
category_id: 8,
price: 14,
image: "http://loremflickr.com/400/300?random=17",
created_at: "2019-07-16 10:12:27",
updated_at: "2019-07-16 10:12:27",
qty: 1
}
]
答案 0 :(得分:0)
如我所见,您没有使用
use Sessions;
在控制器页面顶部。
或尝试使用Session::flush();