Skip to content

Twom2020/laravel-taggable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel File Manager

Installation:

composer require twom/laravel-taggable

You must add the service provider to config/app.php

'providers' => [
	 // for laravel 5.8 and below
	 \Twom\Taggable\TwomTaggableServiceProvider::class,
];

Publish your config file and migrations

php artisan vendor:publish

Run migration

Note: create taggable tables.

php artisan migrate

Config:

config/taggable.php

return [  
    'model' => \Twom\Taggable\Models\Tag::class,
    'filter_condition' => 'where', // can be 'like', this is default condition
];

Lets start to use:

Your taggable model:

Note: should be use the Taggable trait from Twom\Taggable\Traits\Taggable

namespace App;  
  
use Illuminate\Database\Eloquent\Model;  
use Twom\Taggable\Traits\Taggable;  
  
class Post extends Model  
{  
  use Taggable;  
  
  public $timestamps = false;  
  
  protected $fillable = [  
	  'title', // and another fields
  ];  
}

use of taggable options:

/** @var Post $post */
$post = Post::query()->find(1);

//	just add (attach) tags
$post->tag("sport,gym");

//	sync tags, detach all and attach passed tags
$post->stag("football");

//	delete (detach) tags
$post->detag("football");
type example
string "first tag,second tag"
array ["first tag", "second tag"]

About

taggable system in laravel :)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages