Download the PHP package botdigit/laravel-taxonomies without Composer
On this page you can find all versions of the php package botdigit/laravel-taxonomies. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download botdigit/laravel-taxonomies
More information about botdigit/laravel-taxonomies
Files in botdigit/laravel-taxonomies
Package laravel-taxonomies
Short Description Simple, nestable Terms & Taxonomies (similar to WordPress) for Laravel ^ 7.0
License MIT
Homepage https://github.com/ucanbehack/laravel-taxonomies
Informations about the package laravel-taxonomies
Laravel Taxonomies
Simple, nestable Terms & Taxonomies (similar to WordPress) for Laravel 7.
Important Notice
This package is a work in progress, please use with care and feel free to report any issues or ideas you may have!
We've transferred this package to a new owner and therefor updated the namespaces to Botdigit\Taxonomies. The config file is now config/lecturize.php
.
Installation
composer require botdigit/laravel-taxonomies
Require the package from your composer.json
file
and run $ composer update
or both in one with $ composer require botdigit/laravel-taxonomies
.
Next register the service provider and (optional) facade to your config/app.php
file
Configuration & Migration
This will create a config/sluggable.php
, a config/lecturize.php
and a migration file, that you'll have to run like so:
Usage
First, add our HasTaxonomies
trait to your model.
Add a Term
Add multiple Terms
Add a Term with optional parent (taxonomy) & order
Get all Terms for a model by taxonomy
Get a specific Term for a model by (optional) taxonomy
Convenience method for getTerm()
Remove a Term from model by (optional) taxonomy
Remove all Terms from model
Scope models with multiple Terms
Scope models with one Term
Example
Add categories to an Eloquent model
First fo 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.
use Botdigit\Taxonomies\Models\Taxable; use Botdigit\Taxonomies\Models\Taxonomy; use Botdigit\Taxonomies\Models\Term;
$terms = Taxonomy::where('taxonomy', 'tags')->with('term')->get();
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->addTerm('Sheos', 'product_cat');
. Afterwards you want to blog about that product and add that post to a post_cat called Shoes as well, using $product->addTerm('Sheos', 'post_cat');
.
Normally you would have two entries now in your database, one like ['Sheos','product_cat']
and another ['Sheos','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.
License
Licensed under MIT license.
Author
Handcrafted by Tarun in India .
All versions of laravel-taxonomies with dependencies
illuminate/support Version ^7.0
illuminate/database Version ^7.0
cviebrock/eloquent-sluggable Version ^7.0