betterde / response
Application interface response
Fund package maintenance!
betterde.github.io/ects/introduction/more.html
Installs: 1 442
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 2
Open Issues: 0
Requires
- php: ^7.1|^8.0
- ext-json: *
- illuminate/http: ^6.0|^7.0|^8.0|^9.0|^10.0
README
1.Use Trait class in your base controller
use Betterde\Traits\Response\InterfaceResponse;
e.g.
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Betterde\Traits\Response\InterfaceResponse;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, InterfaceResponse;
}
2.Use helper function in your project
- stored
return stored($data, $message = '创建成功');
- updated
return updated($data, $message = '更新成功');
- deleted
return deleted($message = '删除成功');
- accepted
return accepted($message = '请求已接受,等待处理');
- notFound
return notFound($message = '您访问的资源不存在');
- internalError
return internalError($message = '未知错误导致请求失败');
- failed
return failed($message, $code = Response::HTTP_BAD_REQUEST);
- success
return success($data);
- message
return message($message, $code = Response::HTTP_OK);
- respond
return respond($data = [], $message = '请求成功', array $header = []);