{"id":19706735,"url":"https://github.com/unisharp/laravel-taggable","last_synced_at":"2026-02-04T07:08:47.312Z","repository":{"id":57075577,"uuid":"43760083","full_name":"UniSharp/laravel-taggable","owner":"UniSharp","description":null,"archived":false,"fork":false,"pushed_at":"2018-01-22T07:22:39.000Z","size":24,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-15T04:45:19.886Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UniSharp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-06T15:37:47.000Z","updated_at":"2017-01-02T07:02:26.000Z","dependencies_parsed_at":"2022-08-24T14:55:44.434Z","dependency_job_id":null,"html_url":"https://github.com/UniSharp/laravel-taggable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/UniSharp/laravel-taggable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Flaravel-taggable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Flaravel-taggable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Flaravel-taggable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Flaravel-taggable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UniSharp","download_url":"https://codeload.github.com/UniSharp/laravel-taggable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Flaravel-taggable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264890087,"owners_count":23678833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T21:36:41.794Z","updated_at":"2026-02-04T07:08:47.252Z","avatar_url":"https://github.com/UniSharp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Laravel Taggable\n\n### Introduction\n\nthis api can handle tag in independent tables or use only one table \n\n### Install Taggable \n\ncomposer.json:\n\n```json\n\"require\" : {\n    \"unisharp/laravel-taggable\" : \"dev-master\"\n}, \n\"repositories\": {\n    \"type\": \"git\",\n    \"url\": \"https://github.com/UniSharp/laravel-taggable.git\"\n}\n```\n\nsave it and then \n\n```\ncomposer update\n```\n    \n### Configure Taggable\n\n* config/app.php\n\n    * providers:\n\n```php\nUnisharp\\Taggable\\TaggableServiceProvider::class,\n```\n\n### Introduction\n\n* **IndependentTaggable**: it's use independent table to save your tag \n\n    eg. if Product is exists, you can use commad to generate ProductTag Model\n    \n* **IndependentCategorizable**: it's can categorize for your model\n\n#### What different between tag and category?\n\nTag is a many to many relationship, a taggalble entity can tag many tags, and there're many entities can belong a tag.\nHowever, a entity can only belong one category, it's one to one relation, and there're many entities can belong a category.\n     \n### Generate Independent Tag Table\n\nI assume Product model already exists, and you want make this model be taggable. if you don't have any models, you can use following builtin command to generate it\n\n```php\nphp artisan make:model Product --migration\n```\n    \nand use following command to generate tag table and model for your Product\n\n```php\nphp artisan taggable:independent_tag_table Product\n```\n    \nYou will see there's ProductTag model under `app/` folder\n\nNow, add trait for your product model let it be taggable.\n\n```php\nuse Unisharp\\Taggable\\Traits\\IndependentTaggable;\n\nclass Product extends Model\n{\n    use IndependentTaggable\n}\n```\n    \n\n### Use Independent Tag\n\n\n* tag your Model\n\n```php\n$product = Product::find(1);\n$product-\u003etag('new_tag'); // only string\n$product-\u003etag('tag1', 'tag2', 'tag3'); // multi string also work\n$product-\u003etag(['tag1', 'tag2']); // array is acceptable\n```\n\n* untag it\n\n```php\n$product-\u003euntag('new_tag');\n$product-\u003euntag('tag1', 'tag2', 'tag3');\n$product-\u003euntag(['tag1', 'tag2']);\n```\n\n* get your tags\n\n```\n$product-\u003etags // it will return ProductTag back\n```\n        \n* list your entity which belong specified tag\n\n```php\n$tag = ProductTag::find(1);\n$tag-\u003eentities // it will return Products back\n```\n\n### Generate Independent Category\n\nJust like independent tag, you can generate independent category migration by command.\n\n```\nphp artisan taggable:independent_category_table Product\n```\n\nit will generate ProductCategory for Product\n\nand you can add category trait for Product just like before.\n\n```\nuse Unisharp\\Taggable\\Traits\\IndependentIndependentCategorizable;\n\nclass Product extends Model\n{\n    use IndependentCategorizable;\n}\n```\n\n### Use Independent Category\n\n* categorize your model\n\n```php\n$product = Product::find(1);\n$product-\u003ecategorize('free'); // use string\n$product-\u003ecategorize(1); // use product_category id\n```\n     \n* decategorize\n\n```php\n$product-\u003edecategorize();\n```\n\n* list your model's category\n\n```php\n$product-\u003ecatetory // list its category, it return ProductCategory\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funisharp%2Flaravel-taggable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funisharp%2Flaravel-taggable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funisharp%2Flaravel-taggable/lists"}