Start Coding with Codelab | Jaeves AI

Create Laravel Swagger API – Jaeves Codelab

Written by Admin | Oct 2, 2023 10:51:02 PM

Swagger provides us tools to create documentation for our apis and shares their definitions with teams, developers or consumers. Here we will create laravel swagger API documentation.

Install the laravel swagger package using the below commands

composer require "darkaonline/l5-swagger"

If facing version issue then use this command

composer require darkaonline/l5-swagger:*

Now open config/app.php and add this line in providers section.

L5Swagger\L5SwaggerServiceProvider::class,

Now publish L5-Swagger’s config and view files with this commands

php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"

To generate the swagger api documentation run

php artisan l5-swagger:generate

We can also set L5_SWAGGER_GENERATE_ALWAYS = true in .env file to autogenerate the api documentation.

Now we can access our api documentation with this url https://mywebsite.com/api/documentation.

Click here to create Laravel Swagger API

Read laravel swagger documentation here.