What is redirection in Laravel?

0 votes
What is the concept of redirection in laravel?
Mar 18 in Laravel by kartik
• 4,560 points
22 views

1 answer to this question.

0 votes

Named route is used to give specific name to a route. The name can be assigned using the “as” array key.

            Route::get('user/profile', ['as' => 'profile', function () {
             //
            }]);

Note − Here, we have given the name profile to a route user/profile.

Redirecting to Named Routes

Example

Observe the following example to understand more about Redirecting to named routes −

Step 1 − Create a view called test.php and save it at resources/views/test.php.

           <html>
              <body>
                   <h1>Example of Redirecting to Named Routes</h1>
              </body>
           </html>

Step 2 − In routes.php, we have set up the route for test.php file. We have renamed it to testing. We have also set up another route redirect which will redirect the request to the named route testing.

app/Http/routes.php

          Route::get('/test', ['as'=>'testing',function() {
               return view('test2');
           }]);

          Route::get('redirect',function() {
               return redirect()->route('testing');
           });

Step 3 − Visit the following URL to test the named route example.

     http://localhost:8000/redirect

Step 4 − After execution of the above URL, you will be redirected to http://localhost:8000/test as we are redirecting to the named route testing.

Step 5 − After successful execution of the URL, you will receive the following output −

answered Mar 18 by Niroj
• 8,620 points

Related Questions In Laravel

0 votes
1 answer

What is reverse routing in Laravel?

 Laravel reverse routing is generating URL's based ...READ MORE

answered Mar 17 in Laravel by Niraj
39 views
0 votes
1 answer

What is middleware? How can we register middeleware in Laravel?

Middleware acts as a bridge between a ...READ MORE

answered Mar 18 in Laravel by Niroj
• 8,620 points
59 views
0 votes
1 answer

What is CSRF in Laravel?

CSRF stands for Cross Site Request Forgery is ...READ MORE

answered Mar 19 in Laravel by Niroj
• 8,620 points
20 views
0 votes
1 answer

What is the use of Facade Pattern in Laravel?

Hey kartik, Facades provide a static interface to classes that are ...READ MORE

answered Mar 19 in Laravel by Niroj
• 8,620 points
19 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 8,620 points
45 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 8,620 points
29 views
0 votes
1 answer

What are named routes in Laravel?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 8,620 points
21 views
0 votes
1 answer

How to create database migration in Laravel?

Hii, Migrations are like version control for your database, ...READ MORE

answered Mar 23 in Laravel by Niroj
• 8,620 points
29 views
0 votes
1 answer

What is the significant difference between insert() and insertGetId() function in Laravel?

Hello, Insert(): This function is simply used to ...READ MORE

answered Mar 17 in Laravel by Niroj
• 8,620 points
21 views
0 votes
1 answer

What is the concept of controller in Laravel?

Hii, In the MVC framework, the letter ‘C’ ...READ MORE

answered Mar 18 in Laravel by Niroj
• 8,620 points
13 views