PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Laravel redirect to named route

return redirect()->route('home');

Laravel offers an easy way to redirect a user to a specific page. By using the redirect() helper you can easily create a redirect like the following:

return redirect('/home');

This will redirect the user to the /home page of your app. But let's say that you had a named route inside of your routes/web.php, like this:

Route::get('home', 'HomeController@index')->name('home');

If you have a named route, you can easily create a redirect, like so:

return redirect()->route('home');

Now, if you ever change the home route to go to the / page instead of the /home URL, you can update the route:

Route::get('/', 'HomeController@index')->name('home');

And the redirect()->route('home');, will still work; however, the redirect('/home') redirect will no longer work. That's the power of using named routes. You can change the actual URL of the route and your redirects will still work.

BETA Snippet explanation automatically generated by OpenAI:

Here is what the above code is doing:
1. First, it checks if the user is logged in (if not, it redirects to the login page).
2. If the user is logged in, it checks if the user has verified his email (if not, it redirects to the verification page).
3. If

Snippet By Dev Dojo

ยท

Created June 12th, 2021

ยท

Report Snippet