Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up redirection by laravel

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report