usamamuneerchaudhary / laravel-tagify
Laravel 10 的 Eloquent 标签包
1.0.3
2023-02-25 00:50 UTC
Requires
- php: ^8.1
- illuminate/database: >=v10.1.4
- illuminate/support: >=v10.1.4
Requires (Dev)
- orchestra/testbench: ^v8.0.4
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-05 17:14:40 UTC
README
Tagify 是一个简单的 Laravel 标签包
使用此包,您可以轻松地对 Laravel 应用中现有的任何模型进行标签化、取消标签或重新标签化。
以下是一个在模型中启用标签的快速示例
- 此包支持 Laravel 10
- 支持的最低 PHP 版本为 v8.1
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Usamamuneerchaudhary\LaravelTagify\Taggable;
class Lesson extends Model
{
use Taggable;
}
安装
您可以通过 composer 安装此包
composer require usamamuneerchaudhary/laravel-tagify
运行迁移
安装此包后,您可以运行迁移
php artisan migrate
服务提供者
不要忘记在 app.php
中添加 ServiceProvider
Usamamuneerchaudhary\LaravelTagify\TagifyServiceProvider::class,
使用方法及一些基本功能
向模型添加标签
$tags =['Laravel','PHP'];
$model->tag($tags);
取消标签
$model->untag(['Laravel]);
取消所有标签
$model->untag();
将标签重新分配给模型
$model->retag(['Eloquent','mysql']);
获取所有标签
$model->tags;
您还可以使用作用域来获取关联的标签,例如:
App\Model\Lesson::withAllTags(['laravel','php']); //will return if has all tags
App\Model\Lesson::withAnyTags(['laravel','php','python']); //will only return the ones associated, and ignore the
ones which are not.
App\Model\Lesson::hasTags(['laravel','php']); //check if a model has tags
测试
composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件 hello@usamamuneer.me 联系我们,而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。