Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 2 years ago.
0

Try this https://github.com/etrepat/baum Create category model then define hasOne('Category') relation in product model.

Last updated 10 years ago.
0

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 ?

Last updated 10 years ago.
0

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

Last updated 10 years ago.
0

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
Last updated 10 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

m-alinasab m-alinasab Joined 14 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.