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

shahr's avatar
Level 10

Saving a checkbox value and save to the database using Laravel

Hi i have this select checkbox which is the time when i check all the value does pass through it! Now my problem is when i saved into the database it is only one value saved. this is my blade

blade.php

'<div class="col-md-2">\n' +
'<div class="form-group">\n' +
'<div class="custom-control custom-checkbox my-4 mr-sm-2">\n' +
'<?php  $studying = json_decode(auth()->user()->studying, true);?>\n' +
'<input {{ isset($studying[$key]) && $studying[$key] ? 'checked' : ''}} type="checkbox" value="1" class="custom-control-input" name="studying" id="studying">\n' +
'<label class="custom-control-label" for="studying">studying</label>\n' +
'</div>\n' +
'</div>\n' +
'</div>\n' +

'<div class="col-md-2">\n' +
'<div class="form-group">\n' +
'<div class="custom-control custom-checkbox my-4 mr-sm-2">\n' +
'<?php  $studying = json_decode(auth()->user()->studying, true);?>\n' +
'<input {{ isset($studying[$key]) && $studying[$key] ? 'checked' : ''}} type="checkbox" value="1" class="custom-control-input" name="studying" id="studying">\n' +
'<label class="custom-control-label" for="studying">studying</label>\n' +
'</div>\n' +
'</div>\n' +
'</div>\n' +

Controller

    $sundays = $request->input('studying');
    $sundaysArray = array();
    foreach($sundays as $sunday){
        $sundaysArray[] = $sunday;
    }
    $user->studying = json_encode($sundaysArray);
    $user->save();

I want to save like ["on","off"] but it save ["on"]

0 likes
1 reply

Please or to participate in this conversation.