PHP code example of sunnanbei / laravel-response

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

    

sunnanbei / laravel-response example snippets


//通过composr安装package
composer 

use NanBei\Response\Facades\Response;

//请求成功,输出数据,返回200
return Response::success($data);

//请求失败,系统异常,返回500
return Response::error();

//请求失败,返回200
return Response::fail();

//请求成功,返回201
return Response::created();

//请求成功,返回204
return Response::noContent();

//请求成功,返回403
return Response::forbidden();

//请求成功,返回404
return Response::notFound();

//接管异常
···
use NanBei\Response\Exceptions\JsonResponse;

class Handler extends ExceptionHandler
{
    use JsonResponse;
···