Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id | name | cat_parent_id | slug
- --- | ------------------| ------------- | -------------
- 1 | Parent - 1 | NULL | parent-1
- 2 | Parent - 2 | NULL | parent-2
- 3 | Child-1- P - 1 | 1 | ch-1-p-1
- 4 | Child-1- P - 2 | 2 | ch-1-p-2
- 5 | sCh-1-Ch-1-P- 2 | 4 | sch-1-ch-1-p-2
- public function children()
- {
- return $this->hasMany('kblinkedCategory', 'cat_parent_id', 'id');
- }
- public function category(Category $category)
- {
- $categories = $category->first()->children;
- return view('product.list', compact('categories'));
- }
- Route::get('/{category?}','ProductController@category');
- public function children()
- {
- return $this->hasMany('kblinkedCategory', 'cat_parent_id');
- }
- public function category($category) // $category is id of category
- {
- $category = Category::findOrFail($category);
- return view('product.list', compact('categories'));
- }
- @foreach($category->children as $child)
- {{$child->name}}
- @endforeach
- Route::get('{category1}/{category2?}/{category3?}/{category4?}',
- 'ProductController@category');
- public function category(Category $category1, Category $category2 = null,
- Category $category3 = null, Category $category4 = null) {
- $category = collect(func_get_args())->filter()->last();
- $categories = $category->first()->children;
- return view('product.list', compact('categories'));
- }
Add Comment
Please, Sign In to add comment