thaonv / laravel-tagging
Thaonv 可标记。
dev-master
2016-07-03 06:37 UTC
Requires
- php: >=5.5.0
- illuminate/database: >= 5.0
- illuminate/support: >= 5.0
Requires (Dev)
- mockery/mockery: ~0.9
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~4.0
- vlucas/phpdotenv: ~2.0
This package is not auto-updated.
Last update: 2024-09-23 13:59:01 UTC
README
本包不打算以任何方式处理javascript或html。本包仅处理数据库存储和读写。
在标签中使用的字符没有实际限制。它使用slug转换来确定两个标签是否相同(“sugar-free”和“Sugar Free”将视为相同的标签)。标签显示名称将通过Str::title()处理
Composer 安装(针对 Laravel 5)
composer require thaonguyen90/laravel-tagging "~2.0"
安装并运行迁移
服务提供者不会在每次页面加载时加载,因此它不会减慢您的应用程序。
'providers' => array( \Conner\Tagging\Providers\TaggingServiceProvider::class, );
php artisan vendor:publish --provider="Conner\Tagging\Providers\TaggingServiceProvider"
php artisan migrate
完成这两个步骤后,您可以编辑config/tagging.php以使用您首选的设置。
设置您的模型
class Article extends \Illuminate\Database\Eloquent\Model { use \Conner\Tagging\Taggable; }
快速示例用法
$article = Article::with('tagged')->first(); // eager load foreach($article->tags as $tag) { echo $tag->name . ' with url slug of ' . $tag->slug; } $article->tag('Gardening'); // attach the tag $article->untag('Cooking'); // remove Cooking tag $article->untag(); // remove all tags $article->retag(array('Fruit', 'Fish')); // delete current tags and save new tags $article->tagNames(); // get array of related tag names Article::withAnyTag(['Gardening','Cooking'])->get(); // fetch articles with any tag listed Article::withAllTags(['Gardening', 'Cooking'])->get(); // only fetch articles with all the tags Conner\Tagging\Model\Tag::where('count', '>', 2)->get(); // return all tags used more than twice Article::existingTags(); // return collection of all existing tags on any articles
配置
进一步文档
Laravel 4 升级到 5
此库将完整的模型类名存储到数据库中。当您升级laravel并在模型中添加命名空间时,您需要更新数据库中存储的记录。或者,您可以覆盖Model::$morphClass在您的模型类中,以匹配数据库中存储的字符串。
致谢
- Robert Conner - http://smartersoftware.net