title: Undefined variable Laravel Foreach
body: <p>I want to foreach some data but it says it doesn't know the variable:</p>
  
  <p>The error I get:</p>
  
  <pre><code>    ErrorException in dbda158712a631f22ffd888cd244c74e60f3a433.php line 51:
  Undefined variable: albums (View:        /var/www/clients/client2/web2/web/resources/views/album.blade.php)
  </code></pre>
  
  <p>Here is my code: <br>
  <strong>Album.blade.php</strong></p>
  
  <pre><code>@foreach($albums as $others)
      &lt;option value="{{$others-&gt;id}}"&gt;{{$others-&gt;name}}&lt;/option&gt;
  @endforeach
  </code></pre>
  
  <p><strong>My album controller function</strong></p>
  
  <pre><code>  public function getAlbum($id)
    {
      $album = Album::with('Photos')-&gt;find($id);
      return View::make('album')
      -&gt;with('album',$album);
    }
  
    public function getList()
    {
      $albums = Album::with('Photos')-&gt;get();
      return View::make('index')
      -&gt;with('albums',$albums);
    }
  </code></pre>