raymondidema/category
Category table (POSTGRESQL ONLY)
40
3
| Install | |
|---|---|
composer require raymondidema/category |
|
| Latest Version: | 1.0.1 |
| PHP: | >=5.4.0 |
| License: | MIT |
| Last Updated: | Jan 7, 2014 |
| Links: | GitHub · Packagist |
Maintainer: raymond.idema
Category
Category Table (Recursive) (PostgreSQL only)
Installation
composer.json
"require": {
"laravel/framework": "4.1.*",
"raymondidema/category": "dev-master"
},
After updating you could do composer update or composer install
or alternatively composer require raymondidema/category
Config
./app/config/app.php
'providers' => array( 'Raymondidema\Category\CategoryServiceProvider' );
'aliases' => array( 'Menustructure' => 'Raymondidema\Category\Facades\Category' );
Children
Menustructure::table('categories')
->children($id)
->depth(3)
->get();
Optional components
Required
table($table), children($id), childrenWithRoot($id), decendants($id), decendantsWithRoot($id), ancestors($id), breadcrumb($id), get(array('*'))
Optional
depth($integer), where($column, $option), orderBy($column, $ascOrDesc), remember($minutes = null)
Descendants
Menustructure::table('categories')
->decendants($id)
->depth(2)
->where('name', 'aspire')
->get();
Ancestors
Menustructure::table('categories')->ancestors($id)->get(array('name','slug'));
Database layout example
Category requires the following columns: id, parent_id, position
Schema::create('categories', function(Blueprint $table)
{
$table->increments('id');
$table->integer('parent_id')->unsigned()->nullable();
$table->string('name');
$table->string('slug');
$table->integer('position')->unsigned()->nullable();
$table->timestamps();
$table->softDeletes();
});
How to interact with a model
this is not required.
<?php
use \Raymondidema\Category\Models\Reloquent;
class Category extends Reloquent
{
// do stuff here!!!
}