PHP code example of bugsheng / laravel-api-response

1. Go to this page and download the library: Download bugsheng/laravel-api-response 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/ */

    

bugsheng / laravel-api-response example snippets


// 成功携带数据
\ApiRes::success(['info' => ['name' => 'Jone', 'age' => 20]], '数据获取成功');

// 失败携带数据
// 携带自定义错误码
\ApiRes::fail('数据获取失败', ['notice_type' => 1, 'notice_message' => '示例方式'], 10000);
// 不携带错误码 使用默认400错误码
\ApiRes::fail('数据获取失败', ['notice_type' => 1, 'notice_message' => '示例方式']);

// 成功无数据
\ApiRes::message('提交成功');

// 失败无数据
// 携带自定义错误码
\ApiRes::errorMessage('提交失败', 10001);
// 使用默认400错误码
\ApiRes::errorMessage('提交失败');


\Illuminate\Support\Facades\Response::success();
\Illuminate\Support\Facades\Response::fail();

参数与方式一相同