filament/spatie-laravel-tags-plugin
Composer 安装命令:
composer require filament/spatie-laravel-tags-plugin
包简介
Filament support for `spatie/laravel-tags`.
README 文档
README
Installation
Install the plugin with Composer:
composer require filament/spatie-laravel-tags-plugin:"^5.0" -W
If you haven't already done so, you need to publish the migration to create the tags table:
php artisan vendor:publish --provider="Spatie\Tags\TagsServiceProvider" --tag="tags-migrations"
Run the migrations:
php artisan migrate
You must also prepare your Eloquent model for attaching tags.
For more information, check out Spatie's documentation.
Form component
This guide assumes that you've already set up your model to attach tags as per Spatie's documentation.
You may use the field in the same way as the original tags input field:
use Filament\Forms\Components\SpatieTagsInput; SpatieTagsInput::make('tags')
Optionally, you may pass a type() that allows you to group tags into collections:
use Filament\Forms\Components\SpatieTagsInput; SpatieTagsInput::make('tags') ->type('categories')
The tags input supports all the customization options of the original tags input component.
Security: tag types and privilege namespaces
When you do not pass ->type(...) to a SpatieTagsInput, the field matches and attaches tags across every type in your database. Internally, it calls Tag::findFromStringOfAnyType($name), which returns the first existing tag matching by name — regardless of its type. This is convenient for general-purpose tagging, but it has a security implication if you also use tag types as a privilege namespace.
For example, suppose your application stores roles as tags:
$user->attachTag('admin', type: 'role'); // Later, in an authorisation check: if ($user->hasTag('admin', 'role')) { // ... }
If you then render a tags input on the same model without specifying a type — for example, a "Hobbies" field on the user's own profile — a low-privilege user can submit admin into that field. The save callback finds the existing role:admin tag (because it matches the name across all types), attaches it to the user, and the authorisation check now returns true. Autocomplete suggestions from getSuggestions() will also list every tag name in the database when no type is set, so the privileged tag names are visible to the attacker.
To prevent this, do at least one of the following:
-
Always pass
->type(...)on user-facing tag inputs. Restricting the input to a specific type means the save callback usessyncTagsWithType()instead ofsyncTagsWithAnyType(), so tags of other types can never be attached:SpatieTagsInput::make('hobbies') ->type('hobbies')
If you have no need for tag types at all but want the safe scoping, pass
->type(null). The field will then read and write only untyped tags (type IS NULL):SpatieTagsInput::make('tags') ->type(null)
-
Do not use Spatie tag types as a privilege namespace if you also expose a user-editable
SpatieTagsInputon the same model. Store roles and permissions in a dedicated table (e.g.spatie/laravel-permission), or in a separate, never-user-editable model relationship. -
Authorise the field itself with
->disabled()or->hidden()when the user lacks permission to manage tags on the record, paired with a server-side authorisation check.
The same caveat applies to SpatieTagsColumn (editable inline) — pass ->type(...) when the column should be scoped to a single tag type.
Table column
This guide assumes that you've already set up your model attach tags as per Spatie's documentation.
To use the tags column:
use Filament\Tables\Columns\SpatieTagsColumn; SpatieTagsColumn::make('tags')
Optionally, you may pass a type():
use Filament\Tables\Columns\SpatieTagsColumn; SpatieTagsColumn::make('tags') ->type('categories')
The type allows you to group tags into collections.
The tags column supports all the customization options of the original tags column.
Infolist entry
This guide assumes that you've already set up your model attach tags as per Spatie's documentation.
To use the tags entry:
use Filament\Infolists\Components\SpatieTagsEntry; SpatieTagsEntry::make('tags')
Optionally, you may pass a type():
use Filament\Infolists\Components\SpatieTagsEntry; SpatieTagsEntry::make('tags') ->type('categories')
The type allows you to group tags into collections.
The tags entry supports all the customization options of the text entry.
filament/spatie-laravel-tags-plugin 适用场景与选型建议
filament/spatie-laravel-tags-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.88M 次下载、GitHub Stars 达 37, 最近一次更新时间为 2021 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 filament/spatie-laravel-tags-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 filament/spatie-laravel-tags-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.88M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 38
- 点击次数: 19
- 依赖项目数: 40
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2021-08-25