title: Undefined variable: $ Laravel 5
body: <p>This is the code from CategoriesController:</p>
  
  <pre><code> public function index()
  {
      $categories = Category::all();
      return view('/home', compact('categories'));
  }
  </code></pre>
  
  <p>And this is the code that I'm writing to the <code>home.blade.php</code></p>
  
  <pre><code>                @foreach($categories as $cat)
                  @endforeach
  </code></pre>
  
  <p>And then in <code>home.blade.php</code></p>
  
  <p>I'm getting this error: <code>Undefined variable: categories</code></p>
  
  <p>Why this happening ? Everything works fine with Articles but not categories and the code is the same.</p>
  
  <p>Home.blade.php</p>
  
  <pre><code>@extends('app')
  
  @section('content')
  
       &lt;div class="col-md-4 pull-right"&gt;
        &lt;div class="panel panel-primary"&gt;
          &lt;div class="panel-heading"&gt;
            &lt;h3 class="panel-title"&gt;Categories&lt;/h3&gt;
          &lt;/div&gt;
          &lt;div class="panel-body"&gt;
  
                            @foreach($categories as $cat)
                            &lt;div class="col-lg-6"&gt;
                              &lt;ul class="list-unstyled"&gt;
                                  &lt;li&gt;&lt;a href="articles/category/{{  }}"&gt;News&lt;/a&gt;
                                  &lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/div&gt;                          
                            @endforeach
     &lt;/div&gt;
        &lt;/div&gt;     
      &lt;/div&gt;
  
  
    @if(count($articles))
  
      @foreach($articles as $article)
  
  &lt;div class="panel panel-default col-md-8"&gt;
    &lt;div class="panel-heading"&gt;
  
    &lt;h3&gt;{{ $article-&gt;title }}&lt;/h3&gt;
     &lt;small&gt;posted by &lt;a href="users/{{ $article-&gt;author-&gt;name }}"&gt;{{ $article-&gt;author-&gt;name }}&lt;/a&gt; {{ $article-&gt;created_at }}&lt;/small&gt;
    &lt;/div&gt;
    &lt;div class="panel-body"&gt;
    {!! str_limit($article-&gt;body, 1000) !!} 
      &lt;hr&gt;
    &lt;a href="{{ url('/articles/'.$article-&gt;slug) }}"&gt;Read More&lt;/a&gt;   
    &lt;/div&gt;
  &lt;/div&gt;
  
          @endforeach
      @else
          &lt;h1&gt;No articles at the moment.&lt;/h1&gt;
      @endif
      &lt;br&gt;
      {!! $articles-&gt;render() !!}
  @stop
  </code></pre>