PHP code example of amitkolloldey / laravel-taggify

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

    

amitkolloldey / laravel-taggify example snippets




namespace App;

use AmitKD\LaravelTaggify\Taggify;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Taggify;

    protected $fillable = [
        'title'
    ];
}



 $post = \App\Post::findOrFail(2);
 $post->addTags( [ 'Non Existing Tag', 'Spring Framework', 'Java']);



 
  $post = \App\Post::findOrFail(2);
  $tag = Tag::findOrFail(7);
  $post->addTags( [ $tag, 8, 9, 'Java']); // Tag model/ids/name
 
 


 
  $post = \App\Post::findOrFail(2); 
  $tag = Tag::findOrFail(7);
  $post->removeTags([ $tag, 8, 9, 'Java']);
 
 


 
  $post = \App\Post::findOrFail(2); 
  $post->removeAllTags();
 
 


 
  $post = \App\Post::findOrFail(2); 
  $post->reTag(['Python','PHP','php oop']);
 
 


 
  $posts = Post::withAnyTag(['Laravel','Java', 9])->get()->dd();
   
 


 
  $posts = Post::withAllTags(['Laravel','Java', 9])->get()->dd();
   
 



   Tag::popular(5)->get()->dd(); // 5 is how many tags to display
    
  


 
    Tag::unPopular(5)->get()->dd(); // 5 is how many tags to display
     
   



   Tag::unUsed(5)->get()->dd(); // 5 is how many tags to display
    
  



   Tag::usedMoreThan(5)->take(5)->get()->dd(); ; // more then 5 times tag's being used
    
  



   Tag::usedLessThan(5)->take(5)->get()->dd(); // not more then 5 times tag's being used
    
  



   $tag = Tag::findOrFail(7);
   $tag = $tag->items(Post::class)->take(5)->get()->dd();
    
  
bash
php artisan migrate