I am hacking my way through a Laravel project. I am returning a search-filtered databse query with Laravel and applying a pagination, the pagination works, the query works, but the pagination links go to a blank page, only the first page of results is visible. Any hints would be much appreciated:

Controller:

<?
namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Job;
use Carbon\Carbon;

class FilterJobsController extends Controller
{
    /**
     * Show a list of all of the application's users.
     *
     * @return Response
     */

    public function index()
    {

        $bidded = request('bidded');
        $state = request('state');
        $city = request('city');
        $contractor = request('contractor');
        $job = request('job');
        $subjob = request('subjob');

        $jobs = DB::table('jobs')->where([
            ['bidded', '=', $bidded],
            ['state', '=', $state],
            ['city', '=', $city],
            ['contractor', '=', $contractor],
            ['job', '=', $job],
            ['subjob', '=', $subjob],
            ])->paginate(3);

        return view('jobs.index', compact('jobs')->with('links', $links));

    }
}

The blade file:

@extends ('layouts.master')

@section ('content')

    <div class="jobs">
        @foreach(array_chunk($jobs->getCollection()->all(), 3) as $page)
            <div class="leftarrow">❰</div> 
                @foreach ($jobs as $job) 
                   @include ('jobs.job')
                @endforeach

            <div class="pagenumbers">
                {{ $jobs->links() }} <<<<This is the invalid pagination location
            </div> <div class="rightarrow"> <!-- <a href="{{ url('/jobs/') }}"> -->
                    ❱
                <!-- </a> --> </div> <div class="downarrowrow"> <div class="downarrow">❱❱</div> </div>
        @endforeach
    </div>
@endsection

Tthe first page return works in this example with 3 records, it is the rest of the pagination links, eg "page2" that simply links to a blank page.

Yes, appending the query to the pagination was the fix:

$this->validate(request(), [
            'bidded' => 'required',
            'state' => 'required',
            'city' => 'required',
            'contractor' => 'required',
            'job' => 'required',
            'subjob' => 'required',
        ]);

        return view('jobs.index', [
        'jobs' => Job::where([
            ['bidded', request('bidded')],
            ['state', request('state')],
            ['city', request('city')],
            ['contractor', request('contractor')],
            ['job', request('job')],
            ['subjob', request('subjob')], 
            ])->paginate(3)->appends([
                'bidded' => request('bidded'),
                'state' => request('state'),
                'city' => request('city'),
                'contractor' => request('contractor'),
                'job' => request('job'),
                'subjob' => request('subjob'),
        ])
        ]);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.