All Projects β†’ Lecturize β†’ Laravel Taxonomies

Lecturize / Laravel Taxonomies

Licence: mit
Simple, nestable Terms & Taxonomies (similar to WordPress) for Laravel.

Labels

Projects that are alternatives of or similar to Laravel Taxonomies

Nova Advanced Image Field
πŸŒ„πŸ“ A Laravel Nova advanced image field with cropping and resizing using Cropper.js and Intervention Image
Stars: ✭ 67 (-4.29%)
Mutual labels:  laravel
Laravel Api Boilerplate Jwt
A Laravel 5.8 API Boilerplate to create a ready-to-use REST API in seconds.
Stars: ✭ 1,155 (+1550%)
Mutual labels:  laravel
Attendant
Laravel Valet GUI
Stars: ✭ 69 (-1.43%)
Mutual labels:  laravel
Laravel Remember Uploads
Laravel Middleware and helper for remembering file uploads during validation redirects
Stars: ✭ 67 (-4.29%)
Mutual labels:  laravel
Chat Demo
Demo Application for https://github.com/musonza/chat/
Stars: ✭ 67 (-4.29%)
Mutual labels:  laravel
Demo Laravel Json Api
Demo of JSON API integration with a Laravel Application
Stars: ✭ 68 (-2.86%)
Mutual labels:  laravel
Laravel.ru
Please use https://github.com/LaravelRUS/laravel.su instead
Stars: ✭ 66 (-5.71%)
Mutual labels:  laravel
Picasso
Laravel Image Management and Optimization Package
Stars: ✭ 70 (+0%)
Mutual labels:  laravel
Laravel Ecommerce
AvoRed an Open Source Laravel Shopping Cart
Stars: ✭ 1,151 (+1544.29%)
Mutual labels:  laravel
Laravel Botscout
Block malicious scripts using botscout.com protection for your laravel app
Stars: ✭ 69 (-1.43%)
Mutual labels:  laravel
Dreamfactory
DreamFactory API Management Platform
Stars: ✭ 1,148 (+1540%)
Mutual labels:  laravel
Ansible Provisioning Tywin
Generate your Ansible provisioning for Symfony2, Laravel and Node.js projects
Stars: ✭ 67 (-4.29%)
Mutual labels:  laravel
Phpstorm Laravel Live Templates
Laravel Live Templates for PhpStorm
Stars: ✭ 1,157 (+1552.86%)
Mutual labels:  laravel
Lolibrary
πŸ‘—The Lolita Fashion Library πŸ‘’
Stars: ✭ 67 (-4.29%)
Mutual labels:  laravel
Laravel Custom Relation
A custom relation for when stock relations aren't enough.
Stars: ✭ 69 (-1.43%)
Mutual labels:  laravel
Laravel Philips Hue
Laravel Philips Hue package to control your lights with remote support
Stars: ✭ 67 (-4.29%)
Mutual labels:  laravel
Laravel Mentions
End-to-end mentions in Laravel 5.
Stars: ✭ 68 (-2.86%)
Mutual labels:  laravel
Rubel
Rubel is a cms built with Laravel and React.
Stars: ✭ 70 (+0%)
Mutual labels:  laravel
Dark Sky Api
PHP Library for the Dark Sky API.
Stars: ✭ 70 (+0%)
Mutual labels:  laravel
Laravel Shopping Cart
Laravel shopping cart package
Stars: ✭ 69 (-1.43%)
Mutual labels:  laravel

Latest Stable Version Total Downloads License

Laravel Taxonomies

Simple, nestable Terms & Taxonomies (similar to WordPress) for Laravel.

Installation

Require the package from your composer.json file

"require": {
    "lecturize/laravel-taxonomies": "^1.0"
}

and run $ composer update or both in one with $ composer require lecturize/laravel-taxonomies.

Configuration & Migration

$ php artisan vendor:publish --provider="Cviebrock\EloquentSluggable\ServiceProvider"
$ php artisan vendor:publish --provider="Lecturize\Taxonomies\TaxonomiesServiceProvider"

This will publish a config/sluggable.php, a config/lecturize.php and some migration files, that you'll have to run:

$ php artisan migrate

For migrations to be properly published ensure that you have added the directory database/migrations to the classmap in your projects composer.json.

Usage

First, add our HasCategories trait to your model.

<?php namespace App\Models;

use Lecturize\Taxonomies\Contracts\CanHaveCategories;
use Lecturize\Taxonomies\Traits\HasCategories;

class Post extends Model implements CanHaveCategories
{
    use HasCategories;

    // ...
}
?>
Add a Term
$model->addCategory('My Category', 'blog_category')
Add multiple Terms
$model->addCategories(['Add','Multiple','Categories'], 'blog_category')
Add a Term with optional parent_id (taxonomy->id) & sort order
$model->addCategory('My Category', 'blog_category', 1, 2)
Get all Terms for a model by taxonomy
$model->getCategories('taxonomy')
Get a specific Term for a model by (optional) taxonomy
$model->getCategory('My Category', 'blog_category')
See if model has a given category within given taxonomy
$model->hasCategory('My Category', 'blog_category')
Remove a Term from model by (optional) taxonomy
$model->removeCategory('My Category', 'blog_category')
Remove (detach) all categories relations from model
$model->detachCategories()
Scope models with any of the given categories
$model = Model::categorizedIn(['Add','Multiple','Categories'], 'blog_category')->get();
Scope models with one category
$model = Model::categorized('My Category', 'blog_category')->get();

Example

Add categories to an Eloquent model

$post = Post::find(1);

$post->addCategory('My First Category', 'blog_category');
$post->addCategories(['Category Two', 'Category Three'], 'blog_category');

First of all, this snippet will create three entries in your terms table, if they don't already exist:

  • My First Category
  • Category Two
  • Category Three

Then it will create three entries in your taxonomies table, relating the terms with the given taxonomy "category".

And last it will relate the entries from your taxonomies table with your model (in this example a "Post" model) in your pivot table.

Why three tables?

Imagine you have a Taxonomy called post_cat and another one product_cat, the first categorises your blog posts, the second the products in your online shop. Now you add a product to a category (a term) called Shoes using $product->addCategory('Shoes', 'product_cat');. Afterwards you want to blog about that product and add that post to a post_cat called Shoes as well, using $product->addCategory('Shoes', 'post_cat');.

Normally you would have two entries now in your database, one like ['Shoes','product_cat'] and another ['Shoes','post_at']. Oops, now you recognize you misspelled Shoes, now you would have to change it twice, for each Taxonomy.

So I wanted to keep my Terms unique throughout my app, which is why I separated them from the Taxonomies and simply related them.

Changelog

  • [2021-02-09] v1.0 Extended the database tables to support UUIDs (be sure to generate some on your existing models) and better customization. Quite some breaking changes throughout the whole package.

License

Licensed under MIT license.

Author

Handcrafted with love by Alexander Manfred Poellmann in Vienna & Rome.

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].