title: Laravel 4 Pagination not working (ErrorException)
body: <p>I've searched for all solutions to implement pagination successfully, but nothing I've found worked. I'm new to Laravel so I have maybe only one of those basic misunderstandings.</p>
  
  <p>I have created it like it is described in the current documentation. And I get the first page successfully, exactly the content i need, but when i try to use the pagination, clicking on the "next"-arrow, I get an error message:</p>
  
  <pre><code>ErrorException
  Undefined variable: reviews (View: D:\Xampp\htdocs\laravel\app\views\search.blade.php)
  </code></pre>
  
  <p>I know what this generally means but absolutely no idea how to solve this.</p>
  
  <p>This is the form in the view file:</p>
  
  <pre><code>{{ Form::open(array('url' =&gt; '/search', 'class' =&gt; 'search', 'method' =&gt;'GET')) }}
  {{ Form::text('title') }}
  {{ Form::submit('Suche')}}
  {{ Form::close() }}
  </code></pre>
  
  <p>Here is my routes configuration:</p>
  
  <pre><code>Route::any('/search', array('uses' =&gt; 'HomeController@search'));
  </code></pre>
  
  <p>Here is my function in the HomeController:</p>
  
  <pre><code>public function search() {
      $input = Input::get('title');
      if($input &amp;&amp; $input != ''){
          $games = DB::table('games')-&gt;where('name', 'LIKE', "%$input%")-&gt;get();
          foreach ($games as $game) {
              $reviews = DB::table('reviews')-&gt;whereGame_id($game-&gt;id)-&gt;paginate(3);
          }
      }
      return View::make('search', compact('reviews', 'input', 'games'));
  }
  </code></pre>
  
  <p>Here is the view-code of the search.blade.php view, which displays the results:</p>
  
  <pre><code>@section('content')
  &lt;h2&gt;Suchergebnisse&lt;/h2&gt;
      @foreach ($reviews as $review)
          @foreach ($games as $game)
              @if ($game-&gt;id == $review-&gt;game_id)
                  &lt;h3&gt; {{ $game-&gt;name }} &lt;/h3&gt;
              @endif
          @endforeach
          &lt;p&gt;{{ (preg_replace('/\n/i', '&lt;br/&gt;', $review-&gt;body)) }}&lt;/p&gt;
      @endforeach
  {{ $reviews-&gt;appends(array('term' =&gt; $input))-&gt;links() }}
  @stop
  </code></pre>
  
  <p>I thank you beforehand if someone knows why Laravel has a problem with this solution.</p>
  
  <p><strong>Edit:</strong> 
  I've changed the compact-statement and replaced it with an simple array, just like that:</p>
  
  <pre><code>return View::make('search', array('reviews' =&gt; $reviews, 'input' =&gt; $input, 'games' =&gt; $games));
  </code></pre>
  
  <p>Then I've added <code>global $games; global $reviews;</code> to the Controller, so the Error "Undefined variable: reviews" disappeared. Now I've got the following message, but only on page 2, page 1 works fine:</p>
  
  <pre><code>ErrorException
  
  Invalid argument supplied for foreach() (View: D:\Xampp\htdocs\laravel\app\views\search.blade.php)
  </code></pre>