Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

msaied's avatar
Level 10

How To Make pagination without Parameter on URL ( Pretty URL pagination )

Hello I have quiz script so the user should answer every question and click on Next To See Next question I made this with pagination But the problem is the user can jump to other questions without answer it just by change

?page=X

The parameter on URL, so I need a way to hide this Parameter I search but I didn't found any answer :)

0 likes
20 replies
SilenceBringer's avatar

Hi @msaied you can keep the step in session, for example. So after user fill the step - validate the data, store it (in session too, or in db, not sure how it works for you), set next page value in session and render next step

1 like
msaied's avatar
Level 10

Hello @silencebringer ,

this is what I was thinking for but the question is how :D for example

    public function index()
    {
        $users = User::Paginate(10);
        return view('welcome',compact('users'));
    }

and In View

<div class="container">
    <ol>
        @foreach ($users as $user)
            <li>{{ $user->name }}</li>
        @endforeach
    </ol>
</div>
{{$users->links()}}
SilenceBringer's avatar

@msaied I do not understand your example. You show me list of users.

By the way, do you have just next/prev buttons, or you want to show pages too (just disable not available)?

msaied's avatar
Level 10

@silencebringer yeah, I just gave you an example, not real code it big one :D btw if I did next/prev I will get URL with ?page=x number so the user can play with this number and escape next/prev

jlrdw's avatar

Pretty URL won't fix that, you probably need to do the quiz using Ajax.

A pretty URL is still a URL.

What's stopping you from using an if statement to make sure a previous answer was checked or whatever prior to the next question.

Just put a little logic in there to make sure an answer took place.

msaied's avatar
Level 10

@jlrdw So I have to use Ajax pagination and pass page number with hidden input via it ? right

msaied's avatar
Level 10

@jlrdw if yes i found this package to make Json API

https://github.com/spatie/laravel-json-api-paginate
SilenceBringer's avatar

@msaied as example

in routes/web.php

Route::get('quiz', [QuizController::class, 'form'])->name(quiz.form);
Route::post('quiz', [QuizController::class, 'process'])->name(quiz.process);

in QuizController

public function form () {
    $step = session('step', '1');

    $method = 'step' . $step . 'form';

    return $this->{$method};
}


public function step1form () {
    /// render step 1
    return view (step1form);
}

/// methods for every step
public function step1form () {
    ...
}


public function process () {
    $step = session('step', '1');

    $method = 'step' . $step . 'process';

    return $this->{$method};
}

public function step1process () {
    // do validation

    // and every stuff you need

    session(['step' => 2]);

    return redirect(route('quiz.form'));
}

possible will have some mistakes, but it should give you an idea how to implement this. So, 2 endpoints (to display form and to process form submit), and render appropriate step according to step value in session

msaied's avatar
Level 10

@snapey good answer, but I also a pretty URL without any parameter or anything just with quiz slug

Snapey's avatar

Then switch to Livewire component

Snapey's avatar

any other approach would likely not require pagination.

jlrdw's avatar

Like I said above you could set up some if statements.

Pseudocode

If the request does not have this answer then do something

// redirect back with errors or whatever

I've seen many other laravel uses have these types of quizzes.

My first answer was a two part, suggesting Ajax or setting up some good if statements.

Have you looked at some packages on GitHub that do this stuff, and get some ideas from their code on how they handle a non answered question.

Phread's avatar

Create a hidden field on the form that contains the id they are on. Retrieve the field's value, using it to determine the next form, rather than using the parameter. A possible solution....

Please or to participate in this conversation.