novaday-co/laravel-api-response

本包帮助开发者轻松创建API响应

dev-master 2021-08-03 04:18 UTC

This package is auto-updated.

Last update: 2024-09-29 06:03:07 UTC


README

Laravel API Response package

Laravel API 响应

本包帮助开发者轻松创建API响应。向 集合 响应添加额外数据。使用翻译文件设置消息的简短魔法方法。

如何安装

composer require novaday-co/laravel-api-response

如何使用

成功响应

Api::success("Successful Action")->response();

成功响应

Api::success("Successful Action")->response();

失败响应

Api::failure("Failed")->response();

自定义响应

Api::customResponse(201,'Created Successfully',['key'=>'value'])->response();

使用 data

Api::success('Ok',['key'=>'value'])->response();

data 中的外部数据

Api::success('Ok',[ User::all() ])->withData([ Customer::first() ])->response();

data 旁边的外部数据

Api::success('Ok',[ User::all() ])->with([ 'Customers' => Customer::all() ])->response();

设置消息的简短魔法方法

Api::updated()->response();