laravel-taggable maintained by aammui
Description
Assign Category and Tags to a model
Author
Last update
2024/10/03 22:36
(dev-master)
License
Downloads
323
Introduction
Category and Tags are often useful while working working with Laravel Model. This solution enable categories and tags for any Models in Laravel. Here step by step setup is given below.
Content
Step1: Installation
composer require aammui/laravel-taggable
Step2: Publish Migrations assets
php artisan vendor:publish --provider="Aammui\LaravelTaggable\LaravelTaggableServiceProvider"
php artisan migrate
Step3: Use Traits
Add HasCatgory and HasTag Traits in your model.
<?php
namespace App;
use Aammui\LaravelTaggable\Traits\HasCategory;
use Aammui\LaravelTaggable\Traits\HasTag;
class Post extends Model {
use HasCategory, HasTag;
}
Step4: Call from anywhere.
<?php
$post = Post::create(['name'=>'Post']);
$post->addTag('Tags');
$post->addTag(['Tags','Category']);
$post->addCategory('Category');
$post->addCategory(['Category', 'Laravel Category']);
Step5: Display In Blade
<ul>
@foreach($posts->category as $item)
<li>{{$item->name}}</li>
@endforeach
</ul>