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

TimiAde's avatar

Making Checkbox persistent

I need help in making the checkbox checked persisent in building a quiz app with one question per page.

@foreach ($questions as $question)
            
        <p>{{ $question->question }}</p>
        <ul>
            <li>
                {{-- <form action="" method="post"> --}}
                    <input type="checkbox" name="" id="">
                {{-- </form> --}}
               {{$question->option_a}}
            </li>
            <li>
                {{-- <form action="" method="post"> --}}
                    <input type="checkbox" name="" id="">
                {{-- </form> --}}
               {{$question->option_b}}
            </li>
            <li>
                {{-- <form action="" method="post"> --}}
                    <input type="checkbox" name="" id="">
                {{-- </form> --}}
                {{$question->option_c}}
            </li>
            <li>
                {{-- <form action="" method="post"> --}}
                    <input type="checkbox" name="" id="">
                {{-- </form> --}}
                {{$question->option_d}}
            </li>
        </ul>

        @endforeach
public function index()
    {
        //
        $questions = Question::paginate(1);

        return view('question', compact('questions'));
    }
0 likes
4 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

There are no names or id's. But you could build up a session array and use it for final usage.

TimiAde's avatar

@jlrdw please can you send me any link where i can learn to build a session array. thanks

TimiAde's avatar

@jlrdw how can i click a checkbox and save the value in the session driver automatically without post action.

// Via a request instance...
$request->session()->put('key', 'value');
 
// Via the global "session" helper...
session(['key' => 'value']);
  • {{$question->option_a}}
  • ``` am new to laravel

    Please or to participate in this conversation.