How can i redirect after i use transaction and throw new \Exception('Error'); from my code below when i've an error it stop at else{throw new \Exception('Error');} and my if($errors) not working
is their anyway to redirect after throw new \Exception() ?
$errors = false;
DB::transaction(function () use ($count,$request,$a,$errors) {
for ($i=0; $i < $count; $i++) {
$warehouse_products_sell = New Warehouse_products_sell;
$id_w = $request->input('idw');
$id_c = $request->get('id_c')[$i];
$id_p = $request->get('id_p')[$i];
$qty = $request->input('quantity_box')[$i];
$price = $request->input('price')[$i];
$available = $this->check_stock($id_w, $id_p, $qty);
if($available > 0){
$warehouse_products_sell->save();
}else{
echo "error";
$errors = true;
throw new \Exception('Error');
}
}
});
if ($errors) {
return redirect('URL');
}else{
return 'x';
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire