为laravel中的所有模型附加标签的完整包。

维护者

详细信息

github.com/dizatech/tag

源代码

问题

安装: 1

依赖者: 0

建议者: 0

安全: 0

星标: 3

关注者: 3

分支: 1

开放问题: 0

语言:Blade

v1.0.0 2021-06-18 20:36 UTC

This package is auto-updated.

Last update: 2024-09-19 19:29:57 UTC


README

Latest Version on Packagist GitHub issues GitHub stars GitHub forks Total Downloads GitHub license

一个用于管理标签的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);