I have an Online Store project written in Laravel 5.8 and in this project, I have set some sessions at the Controller, like this:
$delivery_types = [];
$conflicting = false;
if ($foundOrder != null) {
foreach ($foundOrder as $key => $value) {
$product = Product::with('uploaded')->wherePrdId($value->id)->select('*')->first();
array_push($delivery_types, $product->prd_delivery);
$prds[] = [
$product,
$value->quantity,
$value->price
];
}
$delivery_types = array_unique($delivery_types);
if (in_array('iran_free_delivery', $delivery_types) && in_array('tehran_free_delivery', $delivery_types)) {
$conflicting = true;
}
if (in_array(null, $delivery_types)) {
Session::put('free' , 'no');
} else if (in_array('iran_free_delivery', $delivery_types) && in_array('tehran_free_delivery', $delivery_types)) {
Session::put('free' , 'city_country');
//Session::put('iran' , '10');
//Session::put('free_notfree' , '13');
} else if (in_array('iran_free_delivery', $delivery_types)) {
Session::put('free' , 'country');
} else if (in_array('tehran_free_delivery', $delivery_types)) {
Session::put('free' , 'city');
} else {
Session::put('free' , '0');
}
} else {
$prds = [];
}
...
return view('frontend.shop.carts.index', compact('conflicting','...')'
And the problem is, whenever the conflicting
re-submits at
checkout.blade.php
, those session that were added before, still gets submitted.
However, it should not submit the OLD session.
So how to do this with Laravel?
I would really appreciate any idea or suggestion from you guy..
Thanks
You have to unset the session variables after one attempt like this
$this->session->unset_userdata('name');
and for multiple data you can:
$array_name = array('username' => '', 'email' => '');
$this->session->unset_userdata($array_name);