承接 priblo/laravel-has-tags 相关项目开发

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

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

priblo/laravel-has-tags

Composer 安装命令:

composer require priblo/laravel-has-tags

包简介

Performance centric model tags trait

README 文档

README

Performance centric model tags trait

Build Status

Trait Usage

Add the trait to any Eloqent model you need to become taggable:

Priblo\LaravelHasTags\Traits\HasTags;

Usage:

$Post = new Post();

// Tag Model
// (Duplicates are automatically handled)
$Post->tag(['tag1', 'tag2', 'tag3', 'tag1']);
// Tag Model with type
$Post->tag(['tag1', 'tag2', 'tag3', 'tag1'], 'hashtag');

// Count ALL tags attached to the model
$Post->tags->count()
// Count ONLY tags with type
$Post->tagsWithType('hashtag')->count()

// Retag model
// Will remove previous tags and add the new ones
// Type is optional
$Post->reTag(['tag5', 'tag6'],'hashtag');
// Removes ALL tags without type from Model
$Post->untag()
// Removes ONLY tags with the specified type from Model
$Post->untag('hashtag')
// Removes ALL tags from model
$Post->untagALL()

// Retrieves all tagged models with the specified tag and type (optional)
$posts = Post::withAnyTag(['tag1'],'hashtag')->get();

// Retrieves all related models according to Tag and type (optional)
// Returns a collection of Priblo\LaravelHasTags\Models\Related
$relatedCollection = Post::getRelatedByTag('tag1', 'hashtag));

Note on types

Every tag has a type, which if unspecified will be NULL, a null type is still a type, which means that using the untag() method will remove ONLY tags with type === NULL. This is a design choice.

Config

Cache

Caching requires a driver which supports tags. File and Database won't work, redis is suggested. Please make sure to either disable caching in the config or use the array driver for local development.

In the has-tags.php config file you can enable/disable caching and set the cache expiration time.

Caching is enabled by default

Install

Requires: Laravel >=5.5 and PHP 7.1

Composer

    composer require priblo/laravel-has-tags

Laravel

This package supports Auto Discovery.

If you have disabled it, you can install this package by adding to the 'providers' array in ./config/app.php

Priblo\LaravelHasTags\LaravelServiceProvider::class,

Then run:

php artisan vendor:publish --provider="Priblo\LaravelHasTags\LaravelServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="Priblo\LaravelHasTags\LaravelServiceProvider" --tag="config"

Then migrate:

php artisan migrate

Why another tagging trait?

At Priblo we couldn't find a suitable tagging trait for Laravel. Each one fell short for some reason or another. Mainly in the performance department. Tags are an important part of Priblo and we needed to get them right. Opting for the Decorator pattern we put an emphasis on caching and performance. We considered contributing to other projects, but none were in line with our design philosophy. So here it is our implementation, hoping it will be useful to someone else.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固