Hi there
I have one problem with categories and sub-categories
I have table like:
ID----- Name---- ParentID
1 ------- A ---------
Using Eloquent you can use a hasMany()
relationship to relate the table to itself.
Try creating a new method on your model, like so:
class Category extends Eloquent
{
...
public function children()
{
return $this->hasMany('Category','ParentId');
}
}
Then you should be able to get a list of sub categories for any given ID.
$categories = Category::where('ID','=','1')->with('children')->get();
Alternatively, the query suggested by deczo in the comments is a lot simpler, I would recommend using this instead.
Category::with('children')->find(1);