定制 softonic/rest-api-nested-resources 二次开发

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

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

softonic/rest-api-nested-resources

最新稳定版本:3.0.0

Composer 安装命令:

composer require softonic/rest-api-nested-resources

包简介

Utilities to work with REST APIs with nested resources

README 文档

README

Latest Version Software License Build Status Total Downloads Average time to resolve an issue Percentage of issues still open

Utilities to work with REST APIs with nested resources

Main features

  • MultiKeyModel: allows to have nested resources with composite primary keys
  • EnsureModelExists: middleware to validate that a resource exists (used to ensure that a parent resource exists)
  • EnsureModelDoesNotExist: middleware to validate that the resource we want to create doesn't already exist
  • SubstituteBindings: a personalization of the Laravel's SubstituteBindings middleware to work with nested resources
  • SplitPutPatchVerbs: trait that allows the controller to split the "update" method into "modify" (PATCH) and "replace" (PUT) CRUDL methods

Installation

You can require the last version of the package using composer

composer require softonic/rest-api-nested-resources

Configuration

  • MultiKeyModel
class UserCommentModel extends MultiKeyModel
{
    /**
     * Identifiers to be hashed and used in the real primary and foreign keys.
     */
    protected static array $generatedIds = [
        'id_user_comment' => [
            'id_user',
            'id_comment',
        ],
    ];
}
  • EnsureModelExists and EnsureModelDoesNotExist
class UserCommentController extends Controller
{
    protected function setMiddlewares(Request $request)
    {
        $this->middleware(
            'App\Http\Middleware\EnsureModelExists:App\Models\User,id_user',
            ['only' => ['store', 'update']]
        );

        $this->middleware(
            'App\Http\Middleware\EnsureModelDoesNotExist:App\Models\UserComment,id_user,id_comment',
            ['only' => 'store']
        );
    }
}
  • SubstituteBindings
use App\Models\UserComment;

class UserCommentController extends Controller
{
    public function show(UserComment $userComment)
    {
        ...
    }
}
  • SplitPutPatchVerbs
use App\Models\UserComment;

class UserCommentController extends Controller
{
    use SplitPutPatchVerbs;

    public function modify(UserComment $userComment, Request $request)
    {
        ...
    }

    public function replace(Request $request, string $id_user, string $id_comment)
    {
        ...
    }
}

Testing

softonic/rest-api-nested-resources has a PHPUnit test suite, and a coding style compliance test suite using PHP CS Fixer.

To run the tests, run the following command from the project folder.

$ docker compose run test

To open a terminal in the dev environment:

$ docker compose run --entrypoint=bash php

License

The Apache 2.0 license. Please see LICENSE for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2022-05-03