Skip to content

dyfun/Laravel-Simple-Tag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Laravel Tag Package

This package is a simple tag package for Laravel. It allows you to add tags to any model in your Laravel application.

Installation

You can install the package via composer:

composer require dyfun/tags

add the service provider to your config/app.php file:

'providers' => [
    ...
    Dyfun\Tags\TagsServiceProvider::class,
    ...
];

run

php artisan migrate

Usage

Apply HasTags trait to a model

<?php

use Illuminate\Database\Eloquent\Model;
use Dyfun\Tags\HasTags;

class File extends Model
{
    use HasTags;
    ...
}

Example:

$file = File::find(1);
$file->attachTag("apple");
$file->attachTags(["apple", "orange", "watermelon"]);

$file->detachTag("apple");
$file->detachTags(["apple", "orange"]);