Laravel Redirect to URL

Today We will see how we can redirect to another page using Laravel redirect().Laravel Redirect to URL

Laravel Redirects are instance of the Illuminate\Http\RedirectResponse. 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.

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.

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.

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.

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

Redirect to Controller Action in Laravel

You can also redirect user to controller action.

return redirect()->action('App\Http\Controllers\UserController@index');

Redirect to Controller Action With Parameters in Laravel

return redirect()->action('App\Http\Controllers\UserController@index', ['id' => 1]);

Redirect with Flashed Session Data in Laravel

You can pass flashed session message while redirecting with routes.

return redirect('home')->with('messgae', 'Welcome to ExpertPHP Tutorials!');



See our More Tutorials 

Netflix clone app using Laravel
Building an Image Gallery with Laravel and React
Login Signup with Laravel
Bill Invoice System in Laravel
Laravel Dependent Dropdown Tutorial With Example
Library Management system in Laravel PHP
How to show Database Records in a Graph chart using Laravel

Leave a Reply

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