如何在DB中将多个复选框保存为整数

I have this in my view:

enter image description here

And i have only one field in my DB and that is driverslicensetype

how to save this to the DB so that whatever types user chooses will save the picked ones like this:

        /* ABCD
         *
         * A: 0 No 1 AM 2 A1 3 A2 4 A;
         * B: 0 No 1 B1 2 B 3 BE
         * C: 0 No 1 C1 2 C1E 3 C 4 CE
         * D: 0 No 1 D1 2 D1E 3 D 4 DE
         */

so if user chooses A and B only the saved number should be 3300

A B and C would be 3230

A B C D would be 3233

B C1 would be 0210

and so on, i hope you understand.

So i have made this in my view:

<div class="col">
    <?php
    $driverslicense_types = [
        'AM',
        'A1',
        'A2',
        'A',
        'B1',
        'B',
        'BE',
        'C1',
        'C1E',
        'C',
        'CE',
        'D1',
        'D1E',
        'D',
        'DE'
    ]
    ?>
    @foreach($driverslicense_types as $type)
        <div class="col-md-3">
            {!! Form::checkbox('driverslicense_type'.$type,'1', false, ['id'=>'driverslicense_type'.$type, 'class' => 'checkbox-style']) !!}
            {!! Form::label('driverslicense_type'.$type, $type, ['id'=>'driverslicense_type'.$type, 'class'=>'checkbox-style-3-label']) !!}
        </div>
    @endforeach
</div>

So now i don't know how to save this in my controller, anyone could help?

The first thing to remember is that checkboxes that are not checked on the form are NOT posted to the script.

Second, if you put the required value in the value="" attribute rather than the default of 1 that you are using you will get some useful data back from the form

Start with your array of types and give each type code the correct value.

/* ABCD
 *
 * A: 0 No 1 AM 2 A1 3 A2 4 A;
 * B: 0 No 1 B1 2 B 3 BE
 * C: 0 No 1 C1 2 C1E 3 C 4 CE
 * D: 0 No 1 D1 2 D1E 3 D 4 DE
 */

$dl_types = [
    'aaas' => ['AM'=>1, 'A1'=>2, 'A2'=>3, 'A'=>4],
    'bees' => ['B1'=>1, 'B'=>2, 'BE'=>3],
    'cees' => ['C1'=>1, 'C1E'=>2, 'C'=>3, 'CE'=>4],
    'dees' => ['D1'=>1, 'D1E'=>2, 'D'=>,3 'DE'=>4]
]

Now use this to load a value into the value="" attribute on the form for each of the checkboxes.

My Laravel is very rusty, so please check this and dont beat me up if I made a syntax error here

@foreach($dl_types as $name => $subarray)
    @foreach ($subarray as $type => $value)
        <div class="col-md-3">
        {!! Form::checkbox($name.'[]',$value, false, ['id'=>'driverslicense_type'.$type, 'class' => 'checkbox-style']) !!}
        {!! Form::label('driverslicense_type'.$type, $type, ['id'=>'driverslicense_type'.$type, 'class'=>'checkbox-style-3-label']) !!}
        </div>
    @endforeach
@endforeach

Now when the form is posted you should get 4 arrays like this in $_POST

$_POST['aaas'][....]
$_POST['bees'][....]
$_POST['cees'][....]
$_POST['dees'][....]

The sub arrays of each of these will contain the values of the checked checkboxes you placed in the value="" attribute for each one.

So as you say under another answer, you only need the largest from each category to get the answer you want regardless of how many aaas for example were checked, you can then do this for each category

$result_string = '';        // init the string

if ( !isset($_POST['aaas'] ) {
    // nothing in the A set was checked
    $result_string .= '0';
} else {
    $result_string .= $_POST['aaas'][count($_POST['aaas']-1);
}

if ( !isset($_POST['bees'] ) {
    $result_string .= '0';
} else {
    $result_string .= $_POST['bees'][count($_POST['bees']-1);
}

if ( !isset($_POST['cees'] ) {
    $result_string .= '0';
} else {
    $result_string .= $_POST['cees'][count($_POST['cees']-1);
}

if ( !isset($_POST['dees'] ) {
    $result_string .= '0';
} else {
    $result_string .= $_POST['dees'][count($_POST['dees']-1);
}

You should end up with a result string containing 4 numeric characters that you can store onto your database.