What is redirection in Laravel

0 votes
What is the concept of redirection in laravel?
Mar 18, 2020 in Laravel by kartik
• 37,520 points
3,017 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, 2020 by Niroj
• 82,840 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, 2020 in Laravel by Niraj
10,599 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, 2020 in Laravel by Niroj
• 82,840 points
2,800 views
0 votes
1 answer

What is CSRF in Laravel?

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

answered Mar 19, 2020 in Laravel by Niroj
• 82,840 points
1,076 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, 2020 in Laravel by Niroj
• 82,840 points
1,635 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

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

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,088 views
0 votes
1 answer

How to install Laravel via composer?

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

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,951 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

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

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,894 views
0 votes
1 answer

What is database migration and how to create database migration in Laravel?

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

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,360 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, 2020 in Laravel by Niroj
• 82,840 points
2,980 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, 2020 in Laravel by Niroj
• 82,840 points
1,278 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP