PHP code example of weiwei / laravel-apidoc

1. Go to this page and download the library: Download weiwei/laravel-apidoc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

weiwei / laravel-apidoc example snippets


    添加 Weiwei\LaravelApiDoc\ApiDocServiceProvider到config/app.php 的providers 中

    如:
    'providers' => [
         /*
         * Package Service Providers...
         */
         .......
        Weiwei\LaravelApiDoc\ApiDocServiceProvider::class,
    ]

return [
    'title' => "APi接口文档",  //文档title
    'version'=>'1.0.0', //文档版本
    'copyright'=>'Powered By Zhangweiwei', //版权信息
    'controller' => [
        //需要生成文档的类
	'App\\Http\\Controllers\\Api\\DemoController'//此控制器demo文件请看下一个步凑中的源码,或者在包根目录下面DemoController.php
    ],
    'filter_method' => [
        //过滤 不解析的方法名称
        '_empty'
    ],
    'return_format' => [
        //数据格式
        'status' => "200/300/301/302",
        'message' => "提示信息",
    ],
    'public_header' => [
        //全局公共头部参数
        //如:['name'=>'version', '



namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

/**
 * @title 测试demo
 * @description 接口说明
 * @group 接口分组
 * @header name:key 
     * @author 开发者
     * @url /api/demo
     * @method GET
     *
     * @header name:device bute1:对象属性1 attribute2:对象属性2
     * @return array:数组值#
     * @return list_user:用户列表@
     * @list_user name:名称 mobile:手机号 list_follow:关注列表@
     * @list_follow user_id:用户id name:名称
     */
    public function index(Request $request)
    {
        //接口代码
        $device = $request->header('device');
        echo json_encode(["code"=>200, "message"=>"success", "data"=>['device'=>$device]]);
    }

    /**
     * @title 登录接口
     * @description 接口说明
     * @author 开发者
     * @url /api/demo
     * @method GET
     * @module 用户模块

     * @param name:name type:int 
bash
    php artisan vendor:publish