namest/taxonomy

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

This package is not auto-updated.

Last update: 2024-09-28 17:07:22 UTC


README

为您的 Laravel 应用提供一个优雅的方式与分类(标签、类别等)交互。

注意:该包仅支持 Laravel 5

安装

步骤 1:安装包

composer require namest/taxonomy

步骤 2:在您的 config/app.php 中注册服务提供者

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

步骤 3:发布包迁移。打开您的终端并输入

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

步骤 4:迁移已发布的迁移

php artisan migrate

步骤 5:通过 artisan 命令在您的终端中创建分类

php artisan make:taxonomy Color

此命令将在数据库中创建一个分类,并使 app/Color.php 中的 Color 模型反映该分类。

步骤 6:阅读下面的 API 并开始 快乐 使用

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();