In this tutorial, we will create a form like radio button in foreach loop laravel and then we will identify which radio buttons are checked according to database values. So from this tutorial, you will learn laravel set radio button is checked based on database value.

Normally we can not select multiple radio button values simultaneously. We can select one radio button value at a time. So if you want to select multiple radio button values, then we should have to use the checkbox and have to make it a custom design like a radio button.

I will use the checkbox and then I will make it a custom design like the radio button and then show you multiple radio button checked laravel blade example.

laravel-multiple-radio-button-checked-example

So let's see the source code of radio button in foreach loop laravel and multiple radio button checked laravel blade example:

@extends('layouts.app')
@push('style')
    <style>
        :root {
            --form-control-color: #0970e6;
            --form-control-disabled: #959495;
            --current-color: #adadad;
            --font-size: 1.5em;
            --transition-time: 120ms;
            }

            *,
            *:before,
            *:after {
            box-sizing: border-box;
        }
        input[type="checkbox"] {
            -webkit-appearance: none;
            appearance: none;
            background-color: var(--form-background);
            margin: 0.1em 0 0;
            font: inherit;
            color: var(--current-color);
            width: 1em;
            height: 1em;
            border: 0.05em solid currentColor;
            border-radius: 50%;
            transform: translateY(-0.075em);
            transition: var(--transition-time) background ease-in-out;
            display: grid;
            place-content: center;
        }

        input[type="checkbox"]:checked {
            border-color: transparent;
            background-color: var(--form-control-color);
        }

        input[type="checkbox"]::before {
            content: "";
            width: 0.25em;
            height: 0.25em;
            transform: scale(0);
            transition: var(--transition-time) transform ease-in-out;
            box-shadow: inset 1em 1em white;
            border-radius: 50%;
        }
        input[type="checkbox"]:checked::before {
            transform: scale(1);
        }
    </style>
@endpush
@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Laravel Multiple Radio Button Checked Example | Laravelia</div>
                 <div class="card-body">
                    <form class="w-px-500 p-3 p-md-3" action="{{ route('user.store') }}" method="post">
                        @csrf
                        <div class="row mb-3">
                            @php
                                $languages = ['php','c#','java','c++'];
                                $selected = ['php','c#'];
                            @endphp
                            <label class="col-sm-3 col-form-label">Language</label>
                            <div class="col-sm-9 mt-2">
                                @foreach ($languages as $language)
                                    <input type="checkbox" name="language[]" value="{{ $language }}" {{ in_array($language,$selected) ? 'checked' : '' }}> {{ ucfirst($language) }}
                                @endforeach
                            </div>
                        </div>
                    
                        <div class="row mb-3">
                            <label class="col-sm-3 col-form-label"></label>
                            <div class="col-sm-9">
                                <button type="submit" class="btn btn-success btn-block text-white">Submit</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

 

Read also: Multiple Radio Button Selection Form In Laravel

 

Conclusion

Hope this radio button in foreach loop laravel tutorial will help. After completing this multiple radio button checked tutorial, your concept will be clear about multiple radio button checked in laravel. Hope this multiple radio button checked laravel blade exampletutorial will clear your concept about laravel set radio button is checked based on database value.