PHP code example of hkp22 / laravel-taggable

1. Go to this page and download the library: Download hkp22/laravel-taggable 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/ */

    

hkp22 / laravel-taggable example snippets


use Hkp22\LaravelTaggable\Traits\Taggable;
use Illuminate\Database\Eloquent\Model as Eloquent;

class Lesson extends Eloquent
{
    use Taggable;
}

'providers' => [
    Hkp22\LaravelTaggable\TaggableServiceProvider::class,
],

$lesson->tag(['laravel', 'php']);

$tags = $tags = Tag::whereIn('slug', ['laravel', 'testing'])->get();

$lesson->tag($tags);

// Un-tag single tag.
$lesson->untag(['laravel']);

// Un-tag all tags.
$lesson->untag();    

// Tag
$lesson->tag(['laravel', 'testing']);

// Re-tag
$lesson->retag(['laravel', 'postgres', 'redis']);

$tag = Tag::first();

$tag->count;

$lessons = Lesson::withAnyTag(['php'])->get();

$lessons = Lesson::withAllTags(['php', 'laravel', 'testing'])->get();