title: Laravel 5 View composer gives me an undefined variable error
body: <p>I am using Laravel 5, I am trying to output categories variable to a view but currently I am getting an undefined variable error.</p>
  
  <p>Here is the code.</p>
  
  <p>Firstly in config/app.php:</p>
  
  <pre><code>'App\Providers\AppServiceProvider',
  </code></pre>
  
  <p>In app/Providers/AppServiceProvider.php:</p>
  
  <pre><code>public function boot()
      {
          View::composer('partials.menu', function($view)
          {
              $view-&gt;with('categories', Category::all());
          });
      }
  </code></pre>
  
  <p>In partials/menu.blade.php:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;Home&lt;/li&gt;
      @foreach($categories as $category)
          &lt;li&gt;&lt;a href="/store/category/{!! $category-&gt;id !!}"&gt;{!! $category-&gt;name !!}&lt;/a&gt;&lt;/li&gt;
      @endforeach
      &lt;li&gt;Basket&lt;/li&gt;
      &lt;li&gt;Checkout&lt;/li&gt;
      &lt;li&gt;Contact Us&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>and in store/products.php:</p>
  
  <pre><code>@include('partials.menu')
  </code></pre>
  
  <p>The exact error I get is: Undefined variable: categories any help resolving this would be appreciated.</p>
  
  <p>Thanks</p>