Skip to main content

Command Palette

Search for a command to run...

Mention the default route files used in Laravel?

Updated
1 min read
Mention the default route files used in Laravel?
R

Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, MySQL, MongoDB. Love collaborating & making a difference

In Laravel, the default route files are typically located in the "routes" directory. There are two main route files in a new Laravel application:

  1. web.php: This file contains routes that are used for web-based interfaces. It includes routes for handling HTTP requests such as GET and POST for rendering views, handling form submissions, etc. You can find this file in the "routes" directory.

     // File: routes/web.php
     Route::get('/', function () {
         return view('welcome');
     });
    
  2. api.php: This file is used for defining routes that are part of your API. These routes are typically stateless and are often used for serving JSON responses. The "api.php" file is also located in the "routes" directory.

     // File: routes/api.php
     Route::middleware('auth:api')->get('/user', function (Request $request) {
         return $request->user();
     });
    

    These files define the routes for your web and API routes by using the Route facade provided by Laravel. You can also create additional route files for better organization and separation of concerns, and then include them in the main route files if needed.

More from this blog

R

Raja Muhammad Asher - Senior Software Engineer - Full Stack Developer

157 posts

Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, ExpressJS, MySQL, MongoDB. Love collaborating & making a difference