redustudio / catagger by ramadani

Create a collection of types
14
1
3
Package Data
Maintainer Username: ramadani
Maintainer Contact: email.ramadani@gmail.com (Ramadani)
Package Create Date: 2016-10-23
Package Last Update: 2016-11-03
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-17 03:01:54
Package Statistics
Total Downloads: 14
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 1
Total Watchers: 3
Total Forks: 0
Total Open Issues: 0

Catagger

Simple way to creating types for item on your Laravel App, such as category and tag for article or product, genre for movie, skill for user, etc.

Installation

In order to install Catagger, just enter on your terminal

$ composer require redustudio/catagger

In config/app.php file, add

Redustudio\Catagger\ServiceProvider::class,

in the providers array and

'Catagger' => Redustudio\Catagger\Facade::class,

to the aliases array.

If you are not using Laravel 5.3, run this command for publishing migration.

$ php artisan vendor:publish --provider="Redustudio\Catagger\ServiceProvider" --tag="migrations"

then

$ php artisan migrate

for migration catagger tables.

Usage

Attaching to Item

// Post
use Redustudio\Catagger\CataggerTrait;

class Post extends Model
{
    use CataggerTrait;

    public function categories()
    {
        return $this->cataggers('category');
    }

    public function tags()
    {
        return $this->cataggers('tag');
    }
}

$category = 'Programming';
Catagger::sync($post->categories(), $category);

$tags = ['PHP', 'Laravel', 'Package'];
Catagger::sync($post->tags(), $tags);

// Movie
use Redustudio\Catagger\CataggerTrait;

class Movie extends Model
{
    use CataggerTrait;

    public function genres()
    {
        return $this->cataggers('genre');
    }
}

$genres = ['Action', 'Adventure', 'Sci-Fi'];
Catagger::sync($movie->genres(), $genres);

Detaching from Item

$genres = ['Action', 'Adventure', 'Sci-Fi'];
Catagger::sync($movie->genres(), $genres);

$genres = ['Action', 'Sci-Fi'];
Catagger::detach($movie->genres(), $genres); // detaching 'Action' and `Sci-Fi`

// detaching all genres
Catagger::detach($movie->genres());

Todo

  • [ ] Unit Test

About ReduStudio

ReduStudio is web development freelancers based in Yogyakarta and East Borneo, Indonesia. We specialise in developing websites and web apps with Laravel, the most popular PHP Framework.

Let's Start Project With Us

Just Contact Us At:

License

The MIT License (MIT). Please see License File for more information.