Home>Article>PHP Framework> How to use swagger in laravel 5.6

How to use swagger in laravel 5.6

藏色散人
藏色散人 forward
2021-03-03 15:42:06 2601browse

Using swagger in laravel 5.6How to use swagger in laravel 5.6

##When writing this article, My laravel version is
Install
composer require darkaonline/l5-swagger Using version ^5.6 for darkaonline/l5-swagger ... - Installing swagger-api/swagger-ui (v3.17.4) - Installing doctrine/annotations (v1.6.0) - Installing zircote/swagger-php (2.0.13) - Installing darkaonline/l5-swagger (5.6.5) ...
Run
php artisan vendor:publish
Select

L5Swagger\L5SwaggerServiceProvider

This

Two files will be added at this time

/config/l5-swagger.php
/resources/views/vendor/l5-swagger/index.blade.php

  • Configuration
  • Add a comment before
  • class
in the

app/Http/Controllers/Controller.php

file


       Run command
       
php artisan l5-swagger:generate
Open your project URLhttp://localhost/api/documentation, you will see that swagger has run successfully, but no API documentation is displayed.

Write documentation

Gethttp://localhost/home

Example:

index

method inHomeControllerWrite the document

/** * @SWG\Get( * path="/home", * summary="用户资料", * @SWG\Response(response=200, description="请求成功"), * @SWG\Response(response=401, description="用户验证失败"), * @SWG\Response(response=500, description="服务器错误") * ) * */ public function index() { return view('home'); }
above and run the command again
php artisan l5-swagger:generate
Go back tohttp://localhost/api/documentation to refresh, the document will be out, it should look like this Appearance


How to use swagger in laravel 5.6Recommended:

The latest five Laravel video tutorials

The above is the detailed content of How to use swagger in laravel 5.6. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete