Try this https://github.com/etrepat/baum Create category model then define hasOne('Category') relation in product model.
Thanks You :)
I installed the following packages. https://github.com/etrepat/baum
How do I get the following output ?
<ul class="task-list">
<li>Electronics
<ul class="task-list">
<li>TV & Home Theater</li>
<li>Tablets & E-Readers</li>
<li>Computers
<ul class="task-list">
<li>Laptops
<ul class="task-list">
<li>PC Laptops</li>
<li>Macbooks (Air/Pro)</li>
</ul>
</li>
<li>Desktops</li>
<li>Monitors</li>
</ul>
</li>
<li>Cell Phones</li>
</ul>
</li>
<li>Health Fitness & Beaty</li>
<li>Small Appliances</li>
<li>Major Appliances</li>
</ul>
To view all the products in a category and sub-categories of products, what should I do ?
It's good that you're using Baum but this is more useful for getting your database and tree organised than the View.
Now basically you want to create a View and use with('categories', $categories) to pass in your top level categories. Then a simple solution is to use Blade to have:
@foreach ($categories as $category)
@if ($category->hasSubCategories())
<!--Subcat HTML using {{$category->subCats()}}-->
@elseif($category->hasProducts())
<!-- Either product HTML or just show the category as the bottom of the tree, depending on your design-->
@endif
@endforeach
HTH
thanks You .
Output Error :
Call to undefined method Baum\Extensions\Query\Builder::hasSubCategories() (View: C:\xampp\htdocs\shopping\app\views\test.blade.php)
Route::get('prod', function(){
$productgroups = Productgroup::all();
return View::make('test')->with('productgroups' , $productgroups);
});
// Blade File
@foreach ($productgroups as $category)
@if ($category->hasSubCategories())
<!--Subcat HTML using {{$category->subCats()}}-->
@elseif($category->hasProducts())
<!-- Either product HTML or just show the category as the bottom of the tree, depending on your design-->
@endif
@endforeach
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community