Search result pagination laravel
<p>My pagination works on the first page correctly. It displays correctly 2 names. When I want to see the other results on the next pages, it will display nothing with my current code. When I make an static array:  </p>

<pre><code> $searchResults = [
            'item1',
            'item2',
            'item3',
            'item4',
            'item5',
            ];
</code></pre>

<p>It will display the array correctly over different pages.
When I make an array from my sql query, it displays nothing on the next pages.
I used var_dump and on the second page, I didn't see anything of my created array.</p>

<p>this is my controller code:</p>

<pre><code>public function zoekdocument(Request $request) //voor het zoeken van software
{

$zoekdocument = \Request::get('zoekdocument');

$searchResult = array();

$searchdoc = \DB::table('visits')-&gt;where('title', 'LIKE', '%' . $zoekdocument . '%')-&gt;paginate();

foreach($searchdoc as $searchdocument){ 

    $filedir = $searchdocument-&gt;pagename; //wordt gedurende loop tot die finisht in de array gezet.

    $searchResult[] = $filedir; //dat wordt hier gedaan.
}

    $currentPage = LengthAwarePaginator::resolveCurrentPage();

    $page = $request-&gt;has('page') ? $request-&gt;get('page') : 1;

    //Create a new Laravel collection from the array data
    $collection = new Collection($searchResult);

    $perPage = 2;

   $currentPageSearchResults = $collection-&gt; slice (($currentPage -1) * $perPage, $perPage)-&gt;all();
    //Create our paginator and pass it to the view
    $paginatedSearchResults= new 

LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage, $page, ['path'  =&gt; $request-&gt;url(),'query' =&gt; $request-&gt;query(),

return view('Documentatie.result', ['results' =&gt; $paginatedSearchResults])-&gt;with('zoekdocument', $zoekdocument);
</code></pre>

<p>This is my view code:</p>

<pre><code>@section('content')

&lt;!-- Striped rows --&gt;
&lt;div class="panel panel-flat"&gt;
  &lt;div class="panel-heading"&gt;
    &lt;h5 class="panel-title text-center"&gt;Documentatie overzicht resultaat&lt;/h5&gt;
    &lt;div class="heading-elements"&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div class="text-center"&gt;
    &lt;h2&gt;Zoekresultaat van: &lt;b&gt;&lt;i&gt;{{$zoekdocument}}&lt;/b&gt;&lt;/i&gt;&lt;/h5&gt;
    &lt;/div&gt;  

 @foreach ($results as $result)
        &lt;p&gt;{{ $result }}&lt;/p&gt;
    @endforeach

    &lt;?php echo $results-&gt;render(); ?&gt;




@endsection
</code></pre>