1. Go to this page and download the library: Download foodineers/laravel-tag 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/ */
foodineers / laravel-tag example snippets
'taggable_model' => App\Models\User::class,
use Foodineers\Tag\Traits\HasTags;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use HasTags;
}
$user->tags; // Collection of Tag models
$user->tags()->attach($tagId); // Attach by ID
$user->tags()->detach($tagId); // Detach by ID
$user->tags()->sync([1, 2, 3]); // Sync tag IDs
// Tag a user
$user->tag('developer');
$user->tag('admin');
// List tags
$user->tags->pluck('name'); // ['developer', 'admin']
// Remove a tag
$user->detag('admin');
// Sync tags (replace all)
$user->tags()->sync([
Tag::name('moderator')->id,
Tag::name('reviewer')->id,
]);
// From a tag: get all tagged models
$tag = Tag::name('developer');
$tag->tagged; // Users (or your taggable model) with this tag