定制 litermi/response 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

litermi/response

最新稳定版本:1.0.21

Composer 安装命令:

composer require litermi/response

包简介

The Response is a package to response api-rest .

README 文档

README

Software License

About

The Response is a package to response api-rest .

Tutorial how create composer package

Installation

Require the litermi/response package in your composer.json and update your dependencies:

composer require litermi/response

Configuration

set provider

'providers' => [
    // ...
    Litermi\Response\Providers\ServiceProvider::class,
],

The defaults are set in config/response.php. Publish the config to copy the file to your own config:

php artisan vendor:publish --provider="Litermi\Response\Providers\ServiceProvider"

Note: this is necessary to you can change default config

Usage

use Litermi\Response\Traits\ResponseTrait;

class Controller extends BaseController
{
    use ResponseTrait;
    //.
    //.
    //.
}
Class ProductController extends Controller
{
    //.
    //.
    //.
    
    public function store(ProductRequest $request){
             
        $successMessage = _('OPERATION_SUCCESSFUL_MESSAGE');
        $errorMessage   = _('AN_ERROR_HAS_OCCURRED_MESSAGE');

        try {
            DB::beginTransaction();

            $product = new Product();
            $product->fill($request->validated());
            $product->save();
            DB::commit();

            $data[ 'product' ] = new ProductResource($product);

            return $this->successResponseWithMessage($data, $successMessage, Response::HTTP_CREATED);

        }
        catch(Exception $exception) {
            DB::rollBack();

            return $this->errorCatchResponse($exception, $errorMessage, Response::HTTP_SERVICE_UNAVAILABLE);
        }
    }

    //.
    //.
    //.
}

License

Released under the MIT License, see LICENSE.

统计信息

  • 总下载量: 3.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-13