eliseekn/laravel-api-response

从您的API发送JSON响应。

v0.0.4 2024-03-05 05:39 UTC

This package is auto-updated.

Last update: 2024-09-05 06:37:14 UTC


README

Latest Version on Packagist Total Downloads

从您的API发送JSON响应。

安装

composer require eliseekn/laravel-api-response

用法

在需要使用的地方添加 MakeApiResponse 特性,并按照以下方式使用:

$this->response('success', 'Lorem ipsum dolor sit amet', 201);
$this->response('warning', [
    'key1' => 'value',
    'key2' => 'value'
], 405);

$this->successResponse('Lorem ipsum dolor sit amet');
$this->successResponse([
    'key1' => 'value',
    'key2' => 'value'
]);

$this->errorResponse(...);