nastuzzi-samy/laravel-model-stages
Composer 安装命令:
composer require nastuzzi-samy/laravel-model-stages
包简介
Add stage scopes to models with parents
README 文档
README
A Laravel package that add some stage scopes on models
Installation
With composer
composer require NastuzziSamy/laravel-model-stages
Docs
This trait add multiple scopes into model class. They are all usable directly by calling them (withtout the "scope" behind) when querying for items. It is usefull for model with parent and children relation in itselft
It is also possible to customize this property:
parent_idto define the parental column
Usage
In your targeted model:
<?php namespace \App\Models; use Illuminate\Database\Eloquent\Model; use NastuzziSamy\Laravel\Traits\HasStages; class User extends Model { use HasStages; /* ... */ }
In your targeted controller:
<?php namespace \App\Http\Controllers; use Illuminate\Routing\Controller; use App\Models\User; class UserController extends Controller { /* ... */ public function index($request) { if ($request->filled('stage')) $users = User::getStage($request->filled('stage')); else if ($request->filled('stages')) $users = User::getStages( // `stages=x,y` => params: [x, y] ...explode(',', $request->filled('stages')) ); else $user = User::get(); return response->json( $users ); } /* ... */ }
Let think we got a company tree with 1 Boss, 2 Supervisors and 4 Employees
Example 1: request /api/users?stage=0
Output:
[
{
"id": 1,
"name": "Boss",
"parent_id": null
},
]
Example 2: request /api/users?stages=0,1
Output:
[
{
"id": 1,
"name": "Boss",
"parent_id": null
},
{
"id": 2,
"name": "Supervisor 1",
"parent_id": 1
},
{
"id": 3,
"name": "Supervisor 2",
"parent_id": 1
},
]
Example 3: request /api/users?stage=2
Output:
[
{
"id": 4,
"name": "Employee 1",
"parent_id": 2
},
{
"id": 5,
"name": "Employee 2",
"parent_id": 2
},
{
"id": 6,
"name": "Employee 3",
"parent_id": 3
},
{
"id": 7,
"name": "Employee 4",
"parent_id": 3
},
]
Changelog
v1.2.1
- Some functions were static
v1.2.0
- Correct wrong variable
- Add posibility to specify a base
v1.1.0
- Add flat and tree print option for stages
v1.0.1
- Correct bad stages
nastuzzi-samy/laravel-model-stages 适用场景与选型建议
nastuzzi-samy/laravel-model-stages 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.73k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「order」 「query」 「model」 「laravel」 「paginate」 「children」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nastuzzi-samy/laravel-model-stages 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nastuzzi-samy/laravel-model-stages 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nastuzzi-samy/laravel-model-stages 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Query filtering in your frontend
Interfaces for web resource models and services to retrieve and create them
Anax Database Active Record module for model classes.
Sylius plugin that adds the possibility to add products to the shopping cart using a button on the product card.
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 2.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-08-02