A full package for attach tags to all of models in laravel.

Maintainers

Details

github.com/dizatech/tag

Source

Issues

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 3

Forks: 1

Open Issues: 0

Language:Blade

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

This package is auto-updated.

Last update: 2024-10-19 19:44:37 UTC


README

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

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

Install and publish files

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 create and edit input components

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

Use index, create and edit pages and customize this pages

  • 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 directory

    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>

Config files options

<?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

Set the Taggable Trait on models

<?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;
}

Attach tags to models

<?php

$post->tags()->sync($request->tags);