Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set up redirection by laravel

Shulou Source: shulou.com Published: 2022-06-03 10:28:59 10月03日 Update

This article mainly shows you "laravel how to set redirection", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "laravel how to set redirection" this article.

Set redirect methods: 1, use "Route::get ()" and redirect () to redirect URL;2, use "redirect ()-> back ()" to redirect back to the previous page; 3, redirect to named route; 4, redirect to controller or controller with parameters; 5, use session data redirection, etc.

The operating environment of this tutorial: windows7 system, Laravel5 version, Dell G3 computer.

Several methods of Laravel redirection

1. Redirect URL

Routing:

Route::get ('itsolutionstuff/tags',' HomeController@tags')

Controller:

Public function home () {return redirect ('itsolutionstuff/tags');}

2. Redirect to the previous page

Public function home () {return back ();} / or public function home2 () {return redirect ()-> back ();}

3. Redirect to a named route

Routing:

Route::get ('itsolutionstuff/tags', array (' as'= > 'itsolutionstuff.tags',' uses' = > 'HomeController@tags'))

Controller:

Public function home () {return redirect ()-> route ('itsolutionstuff.tags');}

Redirect to a named route using parameters

Routing:

Route::get ('itsolutionstuff/tag/ {id}', array ('as'= >' itsolutionstuff.tag', 'uses' = >' HomeController@tags'))

Controller:

Public function home () {return redirect ()-> route ('itsolutionstuff.tag', [' id'= > 17]);}

4. Redirect to controller

Public function home () {return redirect ()-> action ('HomeController@home');}

Redirect to a controller with parameters

Public function home () {return redirect ()-> action ('App\ Http\ Controllers\ HomeController@home', [' id'= > 17]);}

5. Use session data redirection

We can also pass a flashed session message when using routing or url redirection in the controller method, as shown below.

Public function home () {return redirect ('home')-> with (' message', 'Welcome to PHP.cndirection');} above is all the content of the article "how to redirect laravel". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Controller control routing content parameters method article data previous study help use tutorial easy to understand more organization message environment computer knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker Redmi MySQL MariaDB