PHP code example of redustudio / catagger

1. Go to this page and download the library: Download redustudio/catagger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

redustudio / catagger example snippets


Redustudio\Catagger\ServiceProvider::class,

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

// 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);

$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());
bash
$ php artisan migrate