Guest User

Untitled

a guest
Apr 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. id | name | cat_parent_id | slug
  2. --- | ------------------| ------------- | -------------
  3. 1 | Parent - 1 | NULL | parent-1
  4. 2 | Parent - 2 | NULL | parent-2
  5. 3 | Child-1- P - 1 | 1 | ch-1-p-1
  6. 4 | Child-1- P - 2 | 2 | ch-1-p-2
  7. 5 | sCh-1-Ch-1-P- 2 | 4 | sch-1-ch-1-p-2
  8.  
  9. public function children()
  10. {
  11. return $this->hasMany('kblinkedCategory', 'cat_parent_id', 'id');
  12. }
  13.  
  14. public function category(Category $category)
  15. {
  16. $categories = $category->first()->children;
  17.  
  18. return view('product.list', compact('categories'));
  19. }
  20.  
  21. Route::get('/{category?}','ProductController@category');
  22.  
  23. public function children()
  24. {
  25. return $this->hasMany('kblinkedCategory', 'cat_parent_id');
  26. }
  27.  
  28. public function category($category) // $category is id of category
  29. {
  30. $category = Category::findOrFail($category);
  31.  
  32. return view('product.list', compact('categories'));
  33. }
  34.  
  35. @foreach($category->children as $child)
  36. {{$child->name}}
  37. @endforeach
  38.  
  39. Route::get('{category1}/{category2?}/{category3?}/{category4?}',
  40. 'ProductController@category');
  41.  
  42. public function category(Category $category1, Category $category2 = null,
  43. Category $category3 = null, Category $category4 = null) {
  44. $category = collect(func_get_args())->filter()->last();
  45.  
  46. $categories = $category->first()->children;
  47.  
  48. return view('product.list', compact('categories'));
  49. }
Add Comment
Please, Sign In to add comment