定制 robotsinside/laravel-tags 二次开发

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

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

robotsinside/laravel-tags

Composer 安装命令:

composer require robotsinside/laravel-tags

包简介

A package for tagging Laravel Eloquent models.

README 文档

README

Latest Version on Packagist Total Downloads CI License: MIT

A simple package for tagging Eloquent models in Laravel. This package is a sibling of Laravel Categories, which can be used to categorise Eloquent models. The API is the same as this one.

Installation

  1. Install using Composer
composer require robotsinside/laravel-tags
  1. Register the service provider in config/app.php
/*
* Package Service Providers...
*/
\RobotsInside\Tags\TagsServiceProvider::class,

Auto-discovery is enabled, so this step can be skipped.

  1. Publish the migrations
php artisan vendor:publish --provider="RobotsInside\Tags\TagsServiceProvider" --tag="migrations"
  1. Migrate the database. This will create two new tables; tags and taggables
php artisan migrate

Usage

Use the RobotsInside\Tags\Taggable trait in your models.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use RobotsInside\Tags\Taggable;

class Post extends Model
{
    use Taggable;
}

You are now ready to start tagging. Models can be tagged by passing an integer, array of integers, a model instance or a collection of models.

<?php

use App\Post;
use Illuminate\Support\Facades\Route;
use RobotsInside\Tags\Models\Tag;

Route::get('/', function () {

    // Retrieve a new or existing tag
    $tag1 = (new Tag())->resolve('Tag 1');
    $tag2 = (new Tag())->resolve('Tag 2');

    // Or, retrieve a collection of new or existing tags
    $tags = (new Tag())->resolveAll(['Tag 1', 'Tag 2', 'Tag 3'])

    $post = new Post();
    $post->title = 'My blog';
    $post->save();

    $post->tag($tag1);
    // Or
    $post->tag(['tag-1']);
    // Or
    $post->tag([1, 2]);
    // Or
    $post->tag(Tag::get());
});

Untagging models is just as simple.

<?php

use App\Post;
use Illuminate\Support\Facades\Route;
use RobotsInside\Tags\Models\Tag;

Route::get('/', function () {

    $tag1 = Tag::find(1);

    $post = Post::where('title', 'My blog')->first();

    $post->untag($tag1);
    // Or
    $post->untag(['tag-1']);
    // Or
    $post->untag([1, 2]);
    // Or
    $post->untag(Tag::get());
    // Or
    $post->untag(); // remove all tags
});

Scopes

Each time a RobotsInside\Tags\Models\Tag is used, the count column in the tags table is incremented. When a tag is removed, the count is decremented until it is zero.

This packages comes with a number of pre-defined scopes to make queries against the count column easier, namely >=, >, <= and < contstrains, for example:

  • Tag::usedGte(1);
  • Tag::usedGt(2);
  • Tag::usedLte(3);
  • Tag::usedLt(4);

In addition, a scope on the Taggable model is provided to constrain records created within the given time frame. This scope supports human readable values including days, months and years in both singular and plural formats, for example:

  • Taggable::taggedWithin('7 days');
  • Taggable::taggedWithin('1 month');
  • Taggable::taggedWithin('2 years');

Security

If you discover any security related issues, please email robertfrancken@gmail.com instead of using the issue tracker.

Credits

Coffee Time

Will work for ☕☕☕

Buy Me A Coffee

License

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

robotsinside/laravel-tags 适用场景与选型建议

robotsinside/laravel-tags 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 814 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-09-19