Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davy_yg's avatar
Level 27

Online Shop

Hello,

I am having something strange on this online shop.

navigation.blade.php

<ul class="sf-menu">
      <li class="deeper parent current"><a href="{{ url('/') }}">Home</a></li>
      <li><a href="{{ url('/catalog') }}">Catalog</a></li>
      
      @foreach($categories as $category)
        <li>
          <a href="{{ url('/catalog/'. $category->cat_id)}}">
                                    {{ $category->cat_name }}
                                </a>
          @if($category->subCategories->count() != 0)

            <ul>
            @foreach($category->subCategories as $subcat)

                <li><a href="{{ url('/catalog/'. $category->cat_id .'/'. $subcat->subcat_id)}}">{{ $subcat->subcat_name }}</a></li>

            @endforeach
            </ul>

          @endif

        </li>
      @endforeach
      <li><a href="{{ url('/blog') }}">Blog</a></li>
      <li><a href="{{ url('/contact') }}">Contact</a></li>
    </ul>

In the controller:

StoreController.php

public function index()
 {
    $new_products = Products::latest()->limit(env('NEW_PRODUCT'))->get();
    $popular_products = Products::orderBy('prod_seen', 'desc')->limit(env('POPULAR_PRODUCT'))->get();
    $featured_products = Products::where('prod_featured', 1)->limit(env('FEATURED_PRODUCT'))->get();
    //dd($popular_products);
    return view('store.index', compact('new_products', 'popular_products', 'featured_products'));
 }

When I var_dump the categories there are a lot in it, but I do not know where it comes from. Please gives me some ideas.

Route::get('/', 'StoreController@index');

In the store index it includes navigation.blade.php. This must be something advance. Where does $categories comes from?

Please help.

0 likes
1 reply
siangboon's avatar
Level 54

may be there are some global share variables in AppServiceProvide.php... something like:


        view()->composer('*', 

Please or to participate in this conversation.