Installation:
composer require moox/tag
php artisan mooxtag:install
mooxtag:install command publishes the migration, config, and views for the Tag system.First Use Case:
TagResource in your app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->id('admin')
->resources([
\Moox\Tag\Resources\TagResource::class,
]);
}
/admin/tags.Where to Look First:
config/moox-tag.php – Customize tag behavior (e.g., allowed characters, max tags per item).app/Filament/Resources/TagResource.php – Extend or override default logic.database/migrations/[timestamp]_create_tags_table.php – Modify the tags table schema if needed.Tagging Models:
Taggable trait to attach tags to Eloquent models:
use Moox\Tag\Traits\Taggable;
class Post extends Model
{
use Taggable;
}
$post->tags()->sync(['laravel', 'php', 'filament']);
Filament Integration:
TagsInput:
use Moox\Tag\Forms\Components\TagsInput;
TagsInput::make('tags')->required(),
TagResource to CRUD tags globally.Customizing the Tag System:
TagResource to fetch tags dynamically (e.g., from a different table):
public static function getModel(): string
{
return \App\Models\CustomTag::class;
}
public function scopeWithTag($query, $tag)
{
return $query->whereHas('tags', fn($q) => $q->where('name', $tag));
}
Tagging Relationships:
tag_id column:
$post->tags()->attach($tagId, ['created_at' => now()]);
TagResource:
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->withTrashed();
}
API Endpoints:
TagResource API routes:
Filament::registerApiResources([
\Moox\Tag\Resources\Api\TagResource::class,
]);
Migration Conflicts:
tags table schema after installation, drop and re-run the migration:
php artisan migrate:fresh --env=testing
tags table unless absolutely necessary.Tag Sync Issues:
syncWithoutDetaching() to avoid removing existing tags:
$post->tags()->syncWithoutDetaching(['new-tag']);
$post->tags()->sync($tagIds, ['detach' => false]);
Filament Caching:
php artisan filament:cache:clear
Translation Quirks:
resources/lang/[locale]/moox-tag.php:
return [
'tags' => [
'create' => 'Add New Tag',
],
];
moox-tag language file exists in your locale directory.Permission Denied:
TagResource is included in your Filament panel’s resources() array.TagResource.Custom Tag Validation:
Tag model’s validation rules in app/Models/Tag.php:
protected static function booted()
{
static::updating(function ($tag) {
$tag->name = strtolower($tag->name);
});
}
Tag Events:
TagCreated, TagDeleted) in EventServiceProvider:
public function boot()
{
Tag::created(fn ($tag) => Log::info("New tag: {$tag->name}"));
}
Tag Search:
TagResource:
public static function getSearchResultTitle(Tag $record): string
{
return $record->name;
}
Tag Auto-Completion:
TagsInput component with searchable: true for real-time tag suggestions:
TagsInput::make('tags')->searchable()->required(),
Tag Hierarchies:
Tag model to support parent-child relationships:
public function parent()
{
return $this->belongsTo(Tag::class, 'parent_id');
}
tags table migration to include parent_id.How can I help you explore Laravel packages today?