Not 100% sure what you are doing, but the method for deleting from the session is forget, i.e.
$request->session()->forget('key');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, i'm not able to delete data from the session. There are some data in the session . Now i want to remove one by one based on index value sent form ajax request.
//method to store in session, with ajax request
public function store(Request $request) {
$request->session()->push('product',json_decode($request->product));
return session('product');
}
//method to get data from session
public function getFromSession(Request $request){
$product = $request->session()->get('product');
return $product;
}
//delete method
public function deleteProduct(Request $request){
// dd($request->id);
$request->id is the index value which starts from zero sent from view when user click remove button using
ajax request
}
Route for delete
Route::get('/delete','ProductController@deleteProduct');
in view
//part of code
//getting data from session and looping
<div class="card-body" v-for="(list,index) in cart">
<img :src="list.image" width="80">
index:{{index}} {{list.name}}
<button @click="del(index)">X</button>
</div>
//....
remove(index){
axios.get('/delete',{
params: {
id: index,
}
}).then((response)=>{
//this.cart123.push(product)
});
}
Just what to know how to delete product based on delete from session and remove from page as well. Any help would be greatly appreciated
data in session: on dd($products) }
array:3 [▼
0 => {#225 ▼
+"id": 3
+"name": "Ms. Clarissa Olson Jr."
+"description": "Totam eius qui ut impedit nobis excepturi. Enim consequatur inventore dolorem laboriosam sequi dolore harum quibusdam. Doloribus ad tenetur tenetur et ut."
+"category_id": 6
+"price": 111
+"image": "http://loremflickr.com/400/300?random=75"
+"created_at": "2019-07-16 10:12:27"
+"updated_at": "2019-07-16 10:12:27"
+"qty": 1
}
1 => {#226 ▼
+"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
}
2 => {#227 ▼
+"id": 5
+"name": "Prof. Iliana Mohr"
+"description": "Autem sequi esse laudantium ut ut explicabo enim. Corporis cupiditate dolorum et ratione sequi architecto. Vitae enim ex hic nihil."
+"category_id": 2
+"price": 207
+"image": "http://loremflickr.com/400/300?random=99"
+"created_at": "2019-07-16 10:12:27"
+"updated_at": "2019-07-16 10:12:27"
+"qty": 1
}
]
}
Please or to participate in this conversation.