1. Go to this page and download the library: Download priblo/laravel-has-tags library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
priblo / laravel-has-tags example snippets
Priblo\LaravelHasTags\Traits\HasTags;
$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));