javascript - how to prevent data re entering on database on page refresh on laravel -
i have pos under development , noticed when reload page, re-enters data. how prevent data re entering on page reload?
my controller has code:
public function doaddsales(request $request) { $rules = [ 'customer_name'=>'required|alpha', 'or_number'=>'required', 'payment'=>'required', ]; $validator = validator::make($request->all(),$rules); if ($validator->fails()) { return back()->witherrors($validator); } else { foreach ($request->input('id_item') $id) { $item_id[] = $id; } foreach ($request->input('i_name') $name) { $i_name[] = $name; } foreach ($request->input('id_categ') $categ) { $categ_id[] = $categ; } foreach ($request->input('quan') $quan) { $quantity[] = $quan; } foreach ($request->input('tot') $total) { $each_total[] = $total; } $last = sizeof($request->input('id_item')); $i = 0; while ($i < $last) { $items = item::find($item_id[$i]); $sales = new sales; $sales->or = $request->input('or_number'); $sales->customer_name = $request->input('customer_name'); $sales->item_id = $item_id[$i]; $sales->item_name = $i_name[$i]; $sales->category_id = $categ_id[$i]; $sales->user_id = auth::user()->id; $sales->qty = $quantity[$i]; $sales->total = $each_total[$i]; $sales->save(); db::table('items')->where('id',$item_id[$i]) ->update(['qty'=> $items->qty - $quantity[$i]]); return view ('show_sales')->with(array( 'name'=>$request->input('customer_name'), 'or_no'=>$request->input('or_number'), 'total'=>$request->input('getitemprice'), 'change'=>$request->input('change'), 'orders'=>$i_name[$i], )); $i++; } } }
use redirect following.
suppose redirect route \view\list
, can add following line @ end of function
public function doaddsales(request $request){ ... // code ... return redirect()->to('\view\list')->with('alert-success','records saved successfully'); }
note: redirect route must of get
type.
Comments
Post a Comment