1. Go to this page and download the library: Download bolv88/laravel-tagging 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/ */
// Add this line in your config section
$app->configure('tagging');
// Add this line in your service provider section
$app->register(Conner\Tagging\Providers\LumenTaggingServiceProvider::class);
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