dizatech / tag
为laravel中的所有模型附加标签的完整包。
v1.0.0
2021-06-18 20:36 UTC
Requires
- php: 7.1.*|7.2.*|7.3.*|7.4.*
- laravel/framework: 7.*|8.*
README
一个用于管理标签的laravel包,客户端使用ajax、bootstrap、select2和sweetalert2,模型使用多对多关系。
如何安装和配置 dizatech/tag 包?
composer require dizatech/tag
安装并发布文件
Publish 'lacopa' packages pages: php artisan tag:install --lacopa | --lacopa --force | -l -f | -lf Publish empty pages for another projects: php artisan tag:install --force | -f
使用创建和编辑输入组件
Use this component in your 'create' pages: <x-tag></x-tag> OR set custom properties, defaults: label="برچسبها" name="tags" page="create" <x-tag label="برچسبها" name="tags" page="create"></x-tag> And use this component in your 'edit' pages: <x-tag page="edit" id="{{ $post->id }}" $model="{{ get_class($post) }}"></x-tag>
Use this Blade tag in your page: @tagScripts() OR use this tag in script section of page: @slot('script') @tagScripts() @endslot
使用索引、创建和编辑页面以及自定义这些页面
-
如果你使用
lacopa,请在你的侧边栏中添加以下代码@component('tag::components.sidebar.menu')@endcomponent
-
如果你想在另一个项目中使用
tag package,可以使用/resources/views/vendor/tag目录Use below component in your create page structure: <x-tag-create></x-tag-create> Use below component in your edit page structure: <x-tag-edit tag="{{ $tag->id }}"></x-tag-edit> Use below component in your index page structure: <x-tag-index></x-tag-index>
配置文件选项
<?php return [ // Minimum Input Length for search keyword 'minimumInputLength' => 2, // Recommended: Set your models that has many-to-many-polymorphic relation with Tag model 'morphedByMany' => [ // For example // 'articles' => 'App\Models\Article', ], ]; // Notice: if you update 'morphedByMany' option, use this command each time php artisan tag:reload
在模型上设置 Taggable 特性
<?php namespace Modules\Course\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Dizatech\Tag\Services\Traits\Taggable; class Post extends Model { use HasFactory, SoftDeletes, Taggable; }
将标签附加到模型上
<?php $post->tags()->sync($request->tags);