Reputation: 101
I am inserting data to the database
and redirecting back to the previous page using the code below in laravel
public function store(Request $request)
{
$todo=new Todo;
$todo->todo=$request->todo;
$todo->save();
return redirect()->back();
}
After entering some data "new todo" it works well; data inserted and shows in the page but the page becomes like below.
I think the stylings are not working in the page
And after refreshing the page i got the page well.
What should be the problem?
Upvotes: 0
Views: 1454
Reputation: 1642
You can save the previous URL in session so that you can easily redirect back to their previous URL,
Try this in your function,
public function store(Request $request)
{
$request->session()->put('url.intended',url()->previous());
$todo=new Todo;
$todo->todo=$request->todo;
$todo->save();
return redirect($request->session()->get('url.intended'));
}
Here, the Previous URL is generated by Helpers function of laravel.
Please comment if you have any doubts.
Upvotes: 0