How to Add URL Extension in Laravel using Routes | Advanced Laravel Tutorial

How to Add URL Extension in Laravel using Routes | Advanced Laravel Tutorial

Sharing is caring!

How to Add URL Extension in Laravel using Routes – Advanced Laravel Tutorial

While doing one Laravel project I just wondering that, I can change Laravel route Extension. So I just tried this thing.

Laravel is very very trending web technology in 2018 and I am sure to be in 2019 too.  Laravel framework is worked on MVC structure. All of the controller and views are used using the route.

All the views and the controller can only access with the only route. In Laravel Route is the map that used to navigation and all other task related to controller and view.

Using the normal route.

Just Open your route file in routes/web.php

 

Route::get('/index', 'MainController@index');

This was the common way to called route. This means if We write index in our Address bar than function index was called from MainController.php So our main route is now index.

Now try one more thing in this route.

Route::get('/index.html', 'MainController@index');

Now what I do, Just write “.html” after the route name index. Very simple to change Laravel route extension.

We can use any extension instead of “.html”.

Like using a “.aspx” extension.

Route::get('/index.aspx', 'MainController@index');

OR using “.jsp” extension.

Route::get('/index.jsp', 'MainController@index');

OR using “.py” extension

Route::get('/index.py', 'MainController@index');

OR using “.c” extension.

Route::get('/index.c', 'MainController@index');

 

Also, you can pass parameters in the same way as before. See below example.

Route::get('/index.c/{id}', 'MainController@index');// can change extension as you want like .html  or .aspx or .jsp

// How to Access

//IN CONTROLLER

public function index($id){
   echo $id;
}

 

Also, using the post method

Route::post('/index.c', 'MainController@index'); // can change extension as you want like .html  or .aspx or .jsp

// How to Access

//IN CONTROLLER

public function index(Request $request){
   
}

 

 

 

In short, we can use any extension in our Laravel route. All other things are worked with the same code as current.

How to Add URL Extension in Laravel using Routes | Advanced Laravel Tutorial
Summary
How to Add URL Extension in Laravel using Routes - Advanced Laravel Tutorial
Article Name
How to Add URL Extension in Laravel using Routes - Advanced Laravel Tutorial
Description
How to Add URL Extension in Laravel using Routes | Advanced Laravel Tutorial.While doing one Laravel project I just wondering that, I can change Laravel route Extension. So I just tried this thing.
Author
Publisher Name
Shivay Websolution
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top