aammui / laravel-taggable
Assign Category and Tags to a model
3.0.0
2023-02-16 16:32 UTC
Requires
- php: ^7.1|^8.0
- illuminate/database: ^5.8|^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/support: ^5.8|^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^5.1
This package is auto-updated.
Last update: 2024-11-03 20:47:48 UTC
README
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>