Downloads
Stars
Version
Used for create tags.
composer require muan/laravel-tags
Laravel 5.5 uses Package Auto-Discovery, so does not require you to manually add the ServiceProvider.
'providers' => [
// ...
Muan\Tags\Providers\TagsServiceProvider::class,
// ...
],
// Use trait
use Muan\Tags\Traits\Taggable;
class Post extends Model
{
use Taggable;
// ...
}
// Create tag
$tag = Muan\Tags\Model\Tag::create([
'title' => $title = 'Laravel',
'slug' => str_slug($title)
]);
// Attach tag
$post = App\Post::find(1);
$post->tags()->attach($tag->id);
$tags = ['Laravel', 'Eloquent', 'Tags'];
foreach ($tags as $index => $tag) {
$preparedTag = [
'title' => $tag,
'slug' => str_slug($tag)
];
$tagId = Muan\Tags\Model\Tag::create($prepareTag)->id;
$tags[$index] = $tagId;
}
$post = App\Post::find($id = 1);
$post->tags()->sync($tags);
$tags = App\Post::find(1)->tags;
Create new tag
// Slug is generated automatically using str_slug()
php artisan tag:create "tag title"
Muan Laravel Admin package is licensed under the MIT License.