Last updated on September 19, 2023 by Arshad Ullah
In the Laravel, routes are used to define the URLs for the web application. When a user makes a request to the application, Laravel’s routing system determines which route matches the request and then calls the corresponding controller. The Laravel framework keeps the route files in the routes directory.
In Laravel, we create web routes in web.php from routes directory and API routes in the api.php from routes directory.
There are different route methods in Laravel,
Create Web Route in Laravel:
Creating web routes are quite simple. To create a web route in the Laravel framework, open the web.php from routes directory and add below code.
Route::get('/contact-us', function () {
return view('contact');
});
In the above example of code, we simple create a web route through the get() method which means the Laravel will be accepting incoming request with get type for this route.
This route will be loading the contact.blade.php from the views directory when we open our Laravel application in the browser along with /contact-us.
Example: https://yourdomain.com/contact-us
Look at the another example below,
Route::get('/contact-us', 'ContactUsController@show');
In this example, we have defined a route that is associated with the ‘show’ method within the ‘ContactUsController’ controller. When a user comes on the route then Laravel will be calling the show() metho from ContactUsController
Conclusion:
In this article, we explained that how can we create web routes in the Laravel along with examples.