namest/taxonomy

v0.2 2015-03-05 04:37 UTC

This package is not auto-updated.

Last update: 2024-11-23 18:02:59 UTC


README

Provide an elegant way to interact with taxonomies (tags, category, ...) in your Laravel app.

Note: The package is only support Laravel 5

Installation

Step 1: Install package

composer require namest/taxonomy

Step 2: Register service provider in your config/app.php

return [
    ...
    'providers' => [
        ...
        'Namest\Taxonomy\TaxonomyServiceProvider',
    ],
    ...
];

Step 3: Publish package migrations. Open your terminal and type:

php artisan vendor:publish --provider="Namest\Taxonomy\TaxonomyServiceProvider"

Step 4: Migrate the migration that have been published

php artisan migrate

Step 5: Create taxonomies in your terminal by artisan command

php artisan make:taxonomy Color

This command will create a taxonomy in database and make the Color model in app/Color.php to reflect that taxonomy.

Step 6: Read API below and start happy

API

$tag = new Tag;
$tag->name = 'new tag';
$tag->slug = 'new-tag';
$tag->save();

$childTag = new Tag;
$childTag->name = 'child tag';
$childTag->slug = 'child-tag';

$childTag = $tag->childs->save($childTag);
$parent = $childTag->parent;
$tag = Tag::first();
echo $tag->name;
echo $tag->slug;

$childs = $tag->childs;
// Find tag has slug is 'new-tag'
$tag = Tag::hasSlug('new-tag')->first();