承接 mayoz/laravel-categorizable 相关项目开发

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

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

mayoz/laravel-categorizable

Composer 安装命令:

composer require mayoz/laravel-categorizable

包简介

Polymorphic categorizable for Laravel

README 文档

README

Latest Version on Packagist Software License Build Status StyleCI

Easily add the ability to category your Eloquent models in Laravel 5.

Installation

You can install the package via composer:

composer require mayoz/laravel-categorizable

Register the service provider in your config/app.php configuration file:

'providers' => [
    ...
    Mayoz\Categorizable\CategorizableServiceProvider::class,
    ...
];

You can publish the migration with:

php artisan vendor:publish --provider="Mayoz\Categorizable\CategorizableServiceProvider" --tag="migrations"

The migration has been published you can create the categories and categorizable tables. You are feel free for added new fields that you need. After, run the migrations:

php artisan migrate

Usage

Suppose, you have the Post model as follows:

<?php

namespace App;

use Mayoz\Categorizable\Categorizable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Categorizable;
}

Associate new categories for the Post model:

$post = Post::find(1);

$post->categorize([1, 2, 3, 4, 5]);

return $post;

Now, the post model is associated with categories ids of 1, 2, 3, 4 and 5.

Remove the existing category association for the Post model:

$post = Post::find(1);

$post->uncategorize([3, 5]);

return $post;

The post model is associated with categories ids of 1, 2 and 4.

Rearrange the category relationships for the Post model:

$post = Post::find(1);

$post->recategorize([1, 5]);

return $post;

The post model is associated with categories ids of 1 and 5.

Extending

I suggest, you always extend the Category model to define your relationships directly. Create you own Category model:

<?php

namespace App;

use Mayoz\Categorizable\Category as BaseCategory;

class Category extends BaseCategory
{
    /**
     * Get all posts for the relation.
     *
     * @return \Illuminate\Database\Eloquent\Relations\MorphedByMany
     */
    public function posts()
    {
        return $this->categorized(Post::class);
    }
}

You publish the package config:

php artisan vendor:publish --provider="Mayoz\Categorizable\CategorizableServiceProvider" --tag="config"

This is the contents of the published config file:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Model Namespace
    |--------------------------------------------------------------------------
    |
    | Change these values when you need to extend the default category model
    | or if the user model needs to be served in a different namespace.
    |
    */

    'category' => App\Category::class,

];

That is all. Now let's play for relationship query with the category.

/**
 * Respond the post
 *
 * @param  \App\Category  $category
 * @return \Illuminate\Http\Response
 */
public function index(Category $category)
{
    return $category->posts()->paginate(10);
}

If we did not extend the Category model, as had to use;

/**
 * Respond the post
 *
 * @param  \App\Category  $category
 * @return \Illuminate\Http\Response
 */
public function index(Category $category)
{
    return $category->categorize(Post::class)->paginate(10);
}

License

This package is licensed under The MIT License (MIT).

mayoz/laravel-categorizable 适用场景与选型建议

mayoz/laravel-categorizable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 155 次下载、GitHub Stars 达 4, 最近一次更新时间为 2017 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「polymorphic」 「categorizable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mayoz/laravel-categorizable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mayoz/laravel-categorizable 我们能提供哪些服务?
定制开发 / 二次开发

基于 mayoz/laravel-categorizable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-25