承接 nastuzzi-samy/laravel-model-stages 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

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_id to 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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固