定制 sukohi/cahen 二次开发

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

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

sukohi/cahen

最新稳定版本:2.0.1

Composer 安装命令:

composer require sukohi/cahen

包简介

A PHP package mainly developed for Laravel to manage sort values of DB table automatically.

README 文档

README

A PHP package mainly developed for Laravel to manage sort values of DB table automatically.
(This is for Laravel 5+. For Laravel 4.2)

Installation

Add this package name in composer.json

"require": {
  "sukohi/cahen": "2.*"
}

Execute composer command.

composer update

Register the service provider in app.php

'providers' => [
    ...Others...,  
    Sukohi\Cahen\CahenServiceProvider::class,
]

Also alias

'aliases' => [
    ...Others...,  
    'Cahen'   => Sukohi\Cahen\Facades\Cahen::class
]

Usage

Basic

$model = YourModel::find(1);
\Cahen::move($model)->to('your-column-name', 5);

Up

\Cahen::move($model)->up('your-column-name');

Down

\Cahen::move($model)->down('your-column-name');

to First

\Cahen::move($model)->first('your-column-name');

to Last

\Cahen::move($model)->last('your-column-name');

with Transaction

\DB::beginTransaction();

if(!\Cahen::move($model)->to('your-column-name', 5)) {
	
    \DB::rollback();

}

\DB::commit();

with Where Clause

You can use where clause to sort within specific record(s).

$model = YourModel::find(1);
\Cahen::move($model)
        ->where('column_1', '=', 'value')
        ->where('column_2', 'LIKE', '%value%')
        ->to('your-column-name', 5);

Set data

You can sort within specific record(s) by setting model object.

$moving_id = 1;
$model = YourModel::find($moving_id);
$models = YourModel::where('id', '<', 5)
            ->where('id', '<>', $moving_id)
            ->get();
\Cahen::move($model)
        ->data($models)
        ->to('your-column-name', 3);
  • Note: You can not include a record that has ID is $moving_id in $models.

Alignment

$model = YourModel::orderBy('id', 'ASC')->get();
\Cahen::align($model, 'your-column-name');

About Sort Number

The sort value starts from 0.

License

This package is licensed under the MIT License.

Copyright 2014 Sukohi Kuhoh

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固