<?php
// Table
id - Primary key
name - Name of category
slug - URL friendly category name
parent_category - parent category id
// Eloquent Model
class Category extends Eloquent {
protected $table = 'categories';
protected $guarded = array();
public static $rules = array(
'name' => 'required',
'slug' => 'required|unique:products_categories,slug'
);
public function categories(){
return $this->hasMany('Category', 'parent_category');
}
public function parentCategory(){
return $this->belongsTo('Category', 'parent_category');
}
public function scopeChildrenOf($query, $id = 0){
$query->where('parent_category', '=', $id);
}
public function isCurrentPage(){
if( Request::is('category/'.$this->slug) ){
return true;
}
else {
return false;
}
}
}