Laravel Redirect to URL – onlinecode

Laravel Redirect to URL – onlinecode

In this post we will give you information about Laravel Redirect to URL – onlinecode. Hear we will give you detail about Laravel Redirect to URL – onlinecodeAnd how to use it also give you demo for it if it is necessary.

In this post, i will tell you how to redirect user from one url to another url in many ways.

Laravel Redirects are instance of the IlluminateHttpRedirectResponse. We simply use redirect helper method.

List of Redirect Methods are :

  • Redirect to URL in Laravel
  • Redirect back to previous page in Laravel
  • Redirect to Named Routes in Laravel
  • Redirect to Named Routes with parameters in Laravel
  • Redirect to Controller Action in Laravel
  • Redirect to Controller Action With Parameters in Laravel
  • Redirect with Flashed Session Data in Laravel

Redirect to URL in Laravel

Here i redirect user to user/dashboard.

  1. returnredirect('user/dashboard');
return redirect('user/dashboard');


Redirect back to previous page in Laravel

You can redirect use to previous page by using back method and this is usefull whenever you submit form and after submission you need to redirect their previous page.

  1. returnredirect()->back();
  2.         OR
  3. returnredirect()->back()->withInput();
return redirect()->back();
		OR
return redirect()->back()->withInput();


Redirect to Named Routes in Laravel

if your routes don’t have any parameters and you don’t know the exact url then you can redirect user with named routes.

  1. returnredirect()->route('home');
return redirect()->route('home');


Redirect to Named Routes with parameters in Laravel

This is usefull when you need extra parameters with named route then you can pass it with second argument to route method.

  1. returnredirect()->route('users',[1]);
return redirect()->route('users', [1]);


Redirect to Controller Action in Laravel

You can also redirect user to controller action.

  1. returnredirect()->action('AppHttpControllersUserController@index');
return redirect()->action('AppHttpControllersUserController@index');


Redirect to Controller Action With Parameters in Laravel

  1. returnredirect()->action('AppHttpControllersUserController@index',['id'=>1]);
return redirect()->action('AppHttpControllersUserController@index', ['id' => 1]);


Redirect with Flashed Session Data in Laravel

You can pass flashed session message while redirecting with routes.

  1. returnredirect('home')->with('messgae','Welcome to onlinecode Tutorials!');
return redirect('home')->with('messgae', 'Welcome to onlinecode Tutorials!');

Now you can easily redirect to url by using these methods.

Hope this code and post will helped you for implement Laravel Redirect to URL – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  32  =  35

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US