1. Go to this page and download the library: Download mmanos/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/ */
mmanos / laravel-taggable example snippets
use Mmanos\Taggable\Taggable;
class User extends Eloquent
{
use Taggable;
}
class User extends Eloquent
{
protected $tag_model = 'Tag';
protected $taggable_table = 'user_tags';
}
class User extends Eloquent
{
protected $taggable_table_sync = ['company_id', 'created_at', 'updated_at', 'deleted_at'];
}
$user->tag('Frequent Visitor');
$user->tag('Frequent Visitor', 'Happy');
// or
$user->tag(['Frequent Visitor', 'Happy']);
$user->untag('Frequent Visitor');
$user->untag('Frequent Visitor', 'Happy');
// or
$user->untag(['Frequent Visitor', 'Happy']);
// Fetch all users who have the 'Agent' tag and who have 'Frequent Visitor' or 'Happy'.
$users = User::withTag('Agent')->withAnyTag('Frequent Visitor', 'Happy')->get();
class User extends Eloquent
{
public function tagContext()
{
return $this->company;
}
}
class Tag extends Eloquent
{
public static function applyQueryContext($query, $context)
{
$query->where('company_id', $context->id);
}
public static function applyModelContext($model, $context)
{
$model->company_id = $context->id;
}
}