title: How to pass data to my header in my layouts in laravel?
body: <pre><code>&lt;nav class=&quot;navbar navbar-expand-lg navbar-light fixed-top&quot; id=&quot;mainNav&quot;&gt;
      &lt;div class=&quot;container&quot;&gt;
          &lt;a class=&quot;navbar-brand&quot; href=&quot;{{ route('home.index') }}&quot;&gt;En&lt;/a&gt;
          &lt;button class=&quot;navbar-toggler navbar-toggler-right&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot;
                  data-target=&quot;#navbarResponsive&quot; aria-controls=&quot;navbarResponsive&quot; aria-expanded=&quot;false&quot;
                  aria-label=&quot;Toggle navigation&quot;&gt;
              Menu
              &lt;i class=&quot;fas fa-bars&quot;&gt;&lt;/i&gt;
          &lt;/button&gt;
          &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarResponsive&quot;&gt;
  
              &lt;ul class=&quot;navbar-nav ml-auto&quot;&gt;
                  &lt;li class=&quot;nav-item&quot;&gt;
                      &lt;a class=&quot;nav-link&quot; href=&quot;{{ route('home.index') }}&quot;&gt;Home&lt;/a&gt;
                  &lt;/li&gt;
  
  
                  &lt;li class=&quot;dropdown nav-item&quot;&gt;
                      &lt;a class=&quot;nav-link&quot; data-toggle=&quot;dropdown&quot;&gt;Categories&lt;i class=&quot;icon-arrow&quot;&gt;&lt;/i&gt;&lt;/a&gt;
                      &lt;ul class=&quot;dropdown-menu&quot;&gt;
                          @foreach($categories as $category)
                              &lt;li&gt;
                                  &lt;a href=&quot;/?category={{ $category-&gt;name }}&quot;&gt;
                                      {{ $category-&gt;name }}
                                  &lt;/a&gt;
                              &lt;/li&gt;
  
                          @endforeach
                      &lt;/ul&gt;
                  &lt;/li&gt;
  
  
                  &lt;li class=&quot;nav-item&quot;&gt;
                      &lt;a class=&quot;nav-link&quot; href=&quot;{{ route('about') }}&quot;&gt;About Me&lt;/a&gt;
                  &lt;/li&gt;
  
                  &lt;li class=&quot;nav-item&quot;&gt;
                      &lt;a class=&quot;nav-link&quot; href=&quot;post.html&quot;&gt;Contact&lt;/a&gt;
                  &lt;/li&gt;
  
  
              &lt;/ul&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/nav&gt;
  </code></pre>
  <p>I have the above code in my header which I include in my app.blade.php as <code>@include('user.layouts.header')</code> then I use app.blade.php as my layout.</p>
  <p>How do I pass data to the header so that I can stop getting the below error if that's the reason I'm getting the error!</p>
  <pre><code>Undefined variable: categories (View: /home/alphy/blogEngidaFinal/resources/views/user/layouts/header.blade.php)
  </code></pre>