A laravel package for manage your tags, that use ajax, bootstrap, select2 and sweetalert2 for client side and use from many to many polymorphic relationship in models.
How to install and config dizatech/tag package?
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
-
If you use from
lacopa
add below code in your sidebar:@component('tag::components.sidebar.menu')@endcomponent
-
If you want to use
tag package
in another project, you can use/resources/views/vendor/tag
directoryUse 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
<?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);