定制 james.xue/laravel-sortable 二次开发

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

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

james.xue/laravel-sortable

Composer 安装命令:

composer require james.xue/laravel-sortable

包简介

Sortable behaviour for eloquent models

README 文档

README

This package provides a trait that adds sortable behaviour to an Eloquent model.

The value of the order column of a new record of a model is determined by the maximum value of the order column of all records of that model + 1.

Installation

This package can be installed through Composer.

composer require james.xue/laravel-sortable

Usage

To add sortable behaviour to your model you must:

  1. Use the trait James\Sortable\SortableTrait;;

    Use the trait James\Sortable\Sortable;

  2. Optionally specify which column will be used as the order column. The default is sort_field.

Example

use James\Sortable\SortableTrait;
use James\Sortable\Sortable;

class MyModel extends Eloquent implements Sortable
{

    use SortableTrait;

    public $sortable = [
        'sort_field' => 'view',
        'sort_when_creating' => true,
    ];
    
    ...
}

If you don't set a value $sortable['sort_field'] the package will assume that your order column name will be named sort_field.

If you don't set a value $sortable['sort_when_creating'] the package will automatically assign the highest order number to a new model;

Assuming that the db-table for MyModel is empty:

$myModel = new MyModel();
$myModel->save(); // sort_field for this record will be set to 1

$myModel = new MyModel();
$myModel->save(); // sort_field for this record will be set to 2

$myModel = new MyModel();
$myModel->save(); // sort_field for this record will be set to 3

You can also move a model:

$myModel = new MyModel();
$myModel->where('id', $id)->first()->move('up'); // up、down、top、end

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固