title: Laravel: Undefined variable Posts
body: <p>I am trying to display data using a foreach statement within my system. Now i am passing through the variable 'posts' into my view however i keep receiving the error: Undefined variable: posts (View:.</p>
  
  <p>Search.blade.php </p>
  
  <pre><code> @foreach($posts as $post)
    &lt;option value="{{$post-&gt;distance}}"&gt;{{ $post-&gt;distance}}&lt;/option&gt;
  
   @endforeach
  </code></pre>
  
  <p>SearchController.php</p>
  
  <pre><code>     public function index()
      {
         $posts = Post::all();
         return view('pages.Search')-&gt;with('posts', $posts);
  
       }
  </code></pre>
  
  <p>Now in my PostsController.php i have similar code which returns all the posts. </p>
  
  <p>PostsController.php</p>
  
  <pre><code>  public function index()
     {
      $posts = Post::all();
      return view('posts.index')-&gt;with('posts', $posts);
  
  }
  </code></pre>
  
  <p>Is this going to cause the error, i didnt think it would cause its returning to a completely separate page.</p>