ItSolutionStuff.com

How to Publish API Route File in Laravel 11?

By Hardik Savani β€’ September 4, 2024
Laravel

Hi,

In this short post, we will show you how to publish api route file in laravel 11 framework.

The release of Laravel 11 is around the corner and it is packed with a lot of new features and improvements. Laravel 11 comes with a slimmer application skeleton. Laravel 11 introduce streamlined application structure, per-second rate limiting, health routing etc.

By default in Laravel 11, you will not be able to see the API route file, and you cannot define API routes in Laravel 11. But if you want to define API routes, then you need to publish the API route file using the below command. It will publish the `api.php` file and also install Sanctum. So, let's see the commands:

Laravel 11 provides the following commands to publish API routes.

Laravel Publish API Route File:

You can run the following command to publish the API route file:

php artisan install:api

Now, you can see a new `api.php` file in the routes directory.

routes/api.php

<?php
  
use Illuminate\Auth\Middleware\Authenticate;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
  
Route::get('/user', function (Request $request) {
    return $request->user();
})->middleware(Authenticate::using('sanctum'));

Then you can work on it.

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

How to Publish Config Files in Laravel 11?

Read Now β†’
β˜…

How to Create Interface in Laravel 11?

Read Now β†’
β˜…

How to Create Custom Class in Laravel 11?

Read Now β†’
β˜…

How to Publish the lang Folder in Laravel 11?

Read Now β†’
β˜…

What’s New in Laravel 11: New Features and Latest Updates

Read Now β†’
β˜…

How to Install Laravel 11 Application?

Read Now β†’
β˜…

Laravel Model Created Event Example

Read Now β†’
β˜…

Laravel Migration Remove Auto Increment Example

Read Now β†’
β˜…

How to Drop Unique Constraint in Laravel Migration?

Read Now β†’
β˜…

Laravel Migration Unique Multiple Columns Example

Read Now β†’
β˜…

How to Add Unique Constraint in Laravel Migration?

Read Now β†’
β˜…

Laravel Eloquent Always Load Model Relation Example

Read Now β†’
β˜…

Laravel Eloquent doesntHave() Condition Example

Read Now β†’
β˜…

Laravel Eloquent Group By Year with Sum Example

Read Now β†’