mrlaozhou/laravel-extend

There is no license information available for the latest version (v1.3.5) of this package.

Laravel extend.

v1.3.5 2019-11-29 03:00 UTC

README

compsoer require mrlaozhou/laravel-extend

介绍

Collection

// 实例化
$collecttion = new\Mrlaozhou\Extend\Collection($data);
// 列表结构
$collection->toList();
// 树形结构
$collection->toTree();

Eloquent

use trait \Mrloazhou\Extend\Unlimitedable

<?php namespace App\Models\Data;

use Illuminate\Database\Eloquent\Model;
use Mrlaozhou\Extend\Unlimitedable;

class Category extends Model
{
    use Unlimitedable;

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->setParentColumn('parent_id');
        $this->setOrderColumn('weight');
        $this->setTitleColumn('name');
    }
   
	 /**
	 * 缓存key
	 * @return string
	 */
    protected static function unlimitedCacheKey()
    {
        return 'category.topic';
    }

    /**
     * @return \Mrlaozhou\Extend\Collection
     */
    public static function topic()
    {
        return static::unlimitedCollectionByKeyword('topic');
    }
}

使用

// 获取结合
Category::unlimitedCollection();
// 根据主键ID获取无限极下级结合
Category::unlimitedCollectionById($id);
// 根据关键词获取无限极下级集合
Category::unlimitedCollectionByKeyword($keyword);
// 根据ID获取单一数据
Category::unlimitedCollectionByKeyword($id);
// 根据关键词获取单一数据
Category::unlimitedSingleByKeyword($keyword);