All Projects → rinvex → laravel-tags

rinvex / laravel-tags

Licence: MIT license
Rinvex Taggable is a polymorphic Laravel package, for tag management. You can tag any eloquent model with ease, and utilize the awesomeness of Sluggable, and Translatable models out of the box.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-tags

sticker-finder
⚡ A telegram bot for searching all the stickers (just like @gif).
Stars: ✭ 90 (+291.3%)
Mutual labels:  tagging
flora-on-server
Work collaboratively in IUCN Red List assessments and manage online biodiversity databases, including a graph-based taxonomy system, species traits and habitats, and species occurrences.
Stars: ✭ 13 (-43.48%)
Mutual labels:  taxonomy
gogtags
GNU global compatible source code tagging for golang
Stars: ✭ 42 (+82.61%)
Mutual labels:  tagging
meta-audio
A PHP library to read and write metadata tags to audio files (MP3, ID3, APE, etc)
Stars: ✭ 32 (+39.13%)
Mutual labels:  tagging
mongoid taggable on
Taggable on custom fields for Mongoid
Stars: ✭ 16 (-30.43%)
Mutual labels:  tagging
Raskoh
Raskoh - easy and object oriented way to interact with WordPress custom post types and taxonomies.
Stars: ✭ 12 (-47.83%)
Mutual labels:  taxonomy
worrms
World Register of Marine Species R client
Stars: ✭ 13 (-43.48%)
Mutual labels:  taxonomy
aws-enterprise-naming-tagging-standard
AWS Tagging policy and naming convention for all resources created within any AWS accounts under the AWS Master Account.
Stars: ✭ 48 (+108.7%)
Mutual labels:  tagging
ncbitax2lin
🐞 Convert NCBI taxonomy dump into lineages
Stars: ✭ 113 (+391.3%)
Mutual labels:  taxonomy
Alturos.ImageAnnotation
A collaborative tool for labeling image data for yolo
Stars: ✭ 47 (+104.35%)
Mutual labels:  tagging
metacoder
Parsing, Manipulation, and Visualization of Metabarcoding/Taxonomic data
Stars: ✭ 120 (+421.74%)
Mutual labels:  taxonomy
bio
A lightweight and high-performance bioinformatics package in Golang
Stars: ✭ 80 (+247.83%)
Mutual labels:  taxonomy
multitax
Python package to obtain, parse and explore biological taxonomies (GTDB, NCBI, Silva, Greengenes, OTT)
Stars: ✭ 22 (-4.35%)
Mutual labels:  taxonomy
react-taxonomypicker
A Taxonomy Picker control built with TypeScript for React. Built for use in Office 365 / SharePoint
Stars: ✭ 23 (+0%)
Mutual labels:  taxonomy
venue-taxonomy
The intention of this project is to standardize the list of venue types that represent Digital-Out-of-Home (DOOH) advertising screens within a programmatic OpenRTB 2.5 context. The systematization of DOOH venue types will allow for clearer targeting by media buying platforms across a spectrum of available supply-side platforms offering DOOH inve…
Stars: ✭ 26 (+13.04%)
Mutual labels:  taxonomy
wikitaxa
taxonomy data from Wikipedia/Wikidata/Wikispecies
Stars: ✭ 16 (-30.43%)
Mutual labels:  taxonomy
pytaxize
python port of taxize (taxonomy toolbelt) for R
Stars: ✭ 29 (+26.09%)
Mutual labels:  taxonomy
popoto-examples
Contains a list of Popoto.js examples
Stars: ✭ 121 (+426.09%)
Mutual labels:  taxonomy
Position-Aware-Tagging-for-ASTE
Code and models for the paper " Position-Aware Tagging for Aspect Sentiment Triplet Extraction", EMNLP 2020.
Stars: ✭ 70 (+204.35%)
Mutual labels:  tagging
skos-play
SKOS-Play allows to print SKOS files in HTML or PDF. It also embeds xls2rdf to generate RDF from Excel.
Stars: ✭ 58 (+152.17%)
Mutual labels:  taxonomy

Rinvex Tags

Rinvex Tags is a polymorphic Laravel package, for tag management. You can tag any eloquent model with ease, and utilize the awesomeness of Sluggable, and Translatable models out of the box.

Packagist Scrutinizer Code Quality Travis StyleCI License

Installation

  1. Install the package via composer:

    composer require rinvex/laravel-tags
  2. Publish resources (migrations and config files):

    php artisan rinvex:publish:tags
  3. Execute migrations via the following command:

    php artisan rinvex:migrate:tags
  4. Done!

Usage

To add tags support to your eloquent models simply use \Rinvex\Tags\Traits\Taggable trait.

Manage your tags

Your tags are just normal eloquent models, so you can deal with it like so. There's few more methods added to tag models for your convenience, let's take a look:

// Create new tag by name
app('rinvex.tags.tag')->createByName('My New Tag');

// Create new tag by name, group, and translation
app('rinvex.tags.tag')->createByName('The very new tag', 'blog', 'en');

// Find first tag by name
app('rinvex.tags.tag')->firstByName('My New Tag');

// Find first tag by name, group, and translation
app('rinvex.tags.tag')->firstByName('وسم جديد', 'board', 'ar');

// Find tag(s) by name
app('rinvex.tags.tag')->findByName('My New Tag');

// Find tag(s) by name, group, and translation
app('rinvex.tags.tag')->findByName('وسم جديد', 'board', 'ar');

// Find multiple tags by names array
app('rinvex.tags.tag')->findByName(['Tag One', 'Tag Two']);

// Find multiple tags by delimited names (tag delimiter is customizable)
app('rinvex.tags.tag')->findByName('First Tag, Second Tag, Third Tag');

// Find tag(s) by name or create if not exists
app('rinvex.tags.tag')->findByNameOrCreate('My Brand New Tag');

// Find tag(s) by name, group, and translation or create if not exists
app('rinvex.tags.tag')->findByNameOrCreate(['My Brand New Tag 2', 'My Brand New Tag 3']);

Notes:

  • Rinvex Tags extends and utilizes other awesome packages, to be translatable out of the box using spatie/laravel-translatable, and for automatic Slugging it uses spatie/laravel-sluggable packages. Them them out.
  • Both findByName() and findByNameOrCreate() methods accepts either one or more tags as their first argument, and always return a collection.

Manage your taggable model

The API is intutive and very straightfarwad, so let's give it a quick look:

// Get instance of your model
$post = new \App\Models\Post::find(1);

// Get attached tags collection
$post->tags;

// Get attached tags query builder
$post->tags();

You can attach tags in various ways:

// Single tag id
$post->attachTags(1);

// Multiple tag IDs array
$post->attachTags([1, 2, 5]);

// Multiple tag IDs collection
$post->attachTags(collect([1, 2, 5]));

// Single tag model instance
$tagInstance = app('rinvex.tags.tag')->first();
$post->attachTags($tagInstance);

// Single tag name (created if not exists)
$post->attachTags('A very new tag');

// Multiple delimited tag names (use existing, create not existing)
$post->attachTags('First Tag, Second Tag, Third Tag');

// Multiple tag names array (use existing, create not existing)
$post->attachTags(['First Tag', 'Second Tag']);

// Multiple tag names collection (use existing, create not existing)
$post->attachTags(collect(['First Tag', 'Second Tag']));

// Multiple tag model instances
$tagInstances = app('rinvex.tags.tag')->whereIn('id', [1, 2, 5])->get();
$post->attachTags($tagInstances);

Notes:

  • The attachTags() method attach the given tags to the model without touching the currently attached tags, while there's the syncTags() method that can detach any records that's not in the given items, this method takes a second optional boolean parameter that's set detaching flag to true or false.
  • To detach model tags you can use the detachTags() method, which uses exactly the same signature as the attachTags() method, with additional feature of detaching all currently attached tags by passing null or nothing to that method as follows: $post->detachTags();.
  • You may have multiple tags with the same name and the same locale, in such case the first record found is used by default. This is intended by design to ensure a consistent behavior across all functionality whether you are attaching, detaching, or scoping model tags.

And as you may have expected, you can check if tags attached:

// Single tag id
$post->hasAnyTags(1);

// Multiple tag IDs array
$post->hasAnyTags([1, 2, 5]);

// Multiple tag IDs collection
$post->hasAnyTags(collect([1, 2, 5]));

// Single tag model instance
$tagInstance = app('rinvex.tags.tag')->first();
$post->hasAnyTags($tagInstance);

// Single tag name
$post->hasAnyTags('A very new tag');

// Multiple delimited tag names
$post->hasAnyTags('First Tag, Second Tag, Third Tag');

// Multiple tag names array
$post->hasAnyTags(['First Tag', 'Second Tag']);

// Multiple tag names collection
$post->hasAnyTags(collect(['First Tag', 'Second Tag']));

// Multiple tag model instances
$tagInstances = app('rinvex.tags.tag')->whereIn('id', [1, 2, 5])->get();
$post->hasAnyTags($tagInstances);

Notes:

  • The hasAnyTags() method check if ANY of the given tags are attached to the model. It returns boolean true or false as a result.
  • Similarly the hasAllTags() method uses exactly the same signature as the hasAnyTags() method, but it behaves differently and performs a strict comparison to check if ALL of the given tags are attached.

Advanced usage

Generate tag slugs

Rinvex Tags auto generates slugs and auto detect and insert default translation for you if not provided, but you still can pass it explicitly through normal eloquent create method, as follows:

app('rinvex.tags.tag')->create(['name' => ['en' => 'My New Tag'], 'slug' => 'custom-tag-slug']);

Note: Check Sluggable package for further details.

Smart parameter detection

Rinvex Tags methods that accept list of tags are smart enough to handle almost all kinds of inputs as you've seen in the above examples. It will check input type and behave accordingly.

Retrieve all models attached to the tag

You may encounter a situation where you need to get all models attached to certain tag, you do so with ease as follows:

$tag = app('rinvex.tags.tag')->find(1);
$tag->entries(\App\Models\Post::class)->get();

Query scopes

Yes, Rinvex Tags shipped with few awesome query scopes for your convenience, usage example:

// Single tag id
$post->withAnyTags(1)->get();

// Multiple tag IDs array
$post->withAnyTags([1, 2, 5])->get();

// Multiple tag IDs collection
$post->withAnyTags(collect([1, 2, 5]))->get();

// Single tag model instance
$tagInstance = app('rinvex.tags.tag')->first();
$post->withAnyTags($tagInstance)->get();

// Single tag name
$post->withAnyTags('A very new tag')->get();

// Multiple delimited tag names
$post->withAnyTags('First Tag, Second Tag, Third Tag');

// Multiple tag names array
$post->withAnyTags(['First Tag', 'Second Tag'])->get();

// Multiple tag names collection
$post->withAnyTags(collect(['First Tag', 'Second Tag']))->get();

// Multiple tag model instances
$tagInstances = app('rinvex.tags.tag')->whereIn('id', [1, 2, 5])->get();
$post->withAnyTags($tagInstances)->get();

Notes:

  • The withAnyTags() scope finds posts with ANY attached tags of the given. It returns normally a query builder, so you can chain it or call get() method for example to execute and get results.
  • Similarly there's few other scopes like withAllTags() that finds posts with ALL attached tags of the given, withoutTags() which finds posts without ANY attached tags of the given, and lastly withoutAnyTags() which find posts without ANY attached tags at all. All scopes are created equal, with same signature, and returns query builder.

Tag translations

Manage tag translations with ease as follows:

$tag = app('rinvex.tags.tag')->find(1);

// Update name translations
$tag->setTranslation('name', 'en', 'New English Tag Name')->save();

// Alternatively you can use default eloquent update
$tag->update([
    'name' => [
        'en' => 'New Tag',
        'ar' => 'وسم جديد',
    ],
]);

// Get single tag translation
$tag->getTranslation('name', 'en');

// Get all tag translations
$tag->getTranslations('name');

// Get tag name in default locale
$tag->name;

Note: Check Translatable package for further details.

Changelog

Refer to the Changelog for a full history of the project.

Support

The following support channels are available at your fingertips:

Contributing & Protocols

Thank you for considering contributing to this project! The contribution guide can be found in CONTRIBUTING.md.

Bug reports, feature requests, and pull requests are very welcome.

Security Vulnerabilities

If you discover a security vulnerability within this project, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.

About Rinvex

Rinvex is a software solutions startup, specialized in integrated enterprise solutions for SMEs established in Alexandria, Egypt since June 2016. We believe that our drive The Value, The Reach, and The Impact is what differentiates us and unleash the endless possibilities of our philosophy through the power of software. We like to call it Innovation At The Speed Of Life. That’s how we do our share of advancing humanity.

License

This software is released under The MIT License (MIT).

(c) 2016-2022 Rinvex LLC, Some rights reserved.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].