Reputation: 362
I am making a page in which user will enter task which he/she wants to do in future. When ever after posting the data I refresh the page it makes a new record but I don't want to create a new record upon refreshing that particular page.
Code of my controller is
public function addToDoList(Request $request)
{
$id = DB::table('doctors')->where('name',Auth::user()->name)->first();
if(Input::get('toDo'))
{
ToDoList::create([
'toDoWork' => $request->todolist,
'doctor_id' => $id->id,
]);
}
$request->toDo = null;
$todolists = Doctor::find($id->id)->todolists;
return view('/doctorPanel/doctorHome',['todolists' => $todolists]);
}
Route is
Route::post('/doctorPanel/doctorHome','doctorHomeController@addToDoList')->name('toDoList')->middleware('doctor');
Please tell me what I should do to stop creating record upon refreshing the page.
Upvotes: 0
Views: 31
Reputation: 4040
user redirect instead of return view after creating the record redirect to your list url or route
return redirect()->route('login');
here login is your route or use
return redirect()->back();
Upvotes: 3