medicivn/core 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

medicivn/core

Composer 安装命令:

composer require medicivn/core

包简介

README 文档

README

Medici core package

Helpers

Add MediciCoreHelperServiceProvider to config/app.php, example:

    'providers' => [
        ...
        MediciVN\Core\Providers\MediciCoreHelperServiceProvider::class,
    ],

Functions:

  • upload_images
  • resize_image
  • upload_private_images
  • get_url_private
  • medici_logger
  • generate_random_verification_code
  • upload_image_v2
  • upload_private_image_v2

Upload Image

  • Upload an image
    $disk = Storage::disk(env('FILESYSTEM_CLOUD_PRIVATE', 's3')); // disk driver instance
    $uploader = new Uploader($source, $disk, $path); // uploader instance
    $uploader->setSizes($size); // resize image if required
    $uploader->setFileName($fileName); // want to set a specific file name
    $uploader->upload()->getResult(); // upload and get result

    // or you can chain the methods in one line
    $uploader->setSizes($size)->setFileName($fileName)->upload()->getResult();

    // global function
    upload_image_v2($source, $path, $size, $fileName);

EloquentNestedSet

Automatically update the tree when creating, updating and deleting a node.

How to use:

  • First, a root node must be initialized in your model's table
  • Add use EloquentNestedSet; to your eloquent model, example:
class Category extends Model
{
    use EloquentNestedSet;

    /**
     * The root node id 
     * Default: 1 
     */
    const ROOT_ID = 99999; 

    /**
     * The left position column name
     * Default: 'lft'
     *
     * Note: 'lft' can be a negative number
     */
    const LEFT = 'lft';

    /**
     * The right position column name
     * Default: 'rgt'
     *
     * Note: 'rgt' can be a negative number
     */
    const RIGHT = 'rgt';

    /**
     * The parent's id column name
     * Default: 'parent_id'
     */
    const PARENT_ID = 'parent_id';

    /**
     * The depth column name
     * The depth of a node - nth descendant, it doesn't affect left and right calculation
     * Starting from the root node will have a depth of 0
     * Default: 'depth'
     */
    const DEPTH = 'depth';

    /**
     * The queue connection is declared in your project `config/queue.php`.
     * if QUEUE_CONNECTION and QUEUE are not provided, lft and rgt calculation are synchronized.
     * 
     * Default: null
     */
    const QUEUE_CONNECTION = 'sqs';

    /**
     * Default: null
     */
    const QUEUE = 'your_queue';

Functions

  • getTree: get all nodes and return as nested array
  • getFlatTree: get all nodes and return as flatten array, the child nodes will be sorted after the parent node
  • getAncestors: get all ancestor nodes of current instance
  • getAncestorsTree: get all ancestor nodes of current instance and return as nested array
  • getDescendants: get all descendant nodes of current instance
  • getDescendantsTree: get all descendant nodes of current instance and return as nested array
  • parent: get the parent node to which the current instance belongs
  • children: get the child nodes of the current instance
  • getLeafNodes: get all leaf nodes - nodes with no children

Other

  • buildNestedTree: build a nested tree base on parent_id

Query scopes

Laravel Eloquent Query Scopes

The root node is automatically ignored by a global scope of ignore_root. To get the root node, use withoutGlobalScope('ignore_root').

  • ancestors
  • descendants
  • flattenTree
  • leafNodes

Warning

  • If you are using SoftDelete and intend to stop using it, you must deal with soft deleted records. The tree will be shuffled, and the calculation of lft and rgt may go wrong.
  • SoftDelete is required if you use queue. Because the queue will not run in deleting and deleted events if a record is permanently deleted.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固