Answers for "conditionally checked checkbox laravel blade"

PHP
0

old function use in checkbox selected in laravel blade

// old selected checkbox in blade template using old function
<label class="form-check-inline">
    <input class="form-check-input" type="checkbox" name="hobby[]" value="1" 
	{{ (is_array(old('hobby')) && in_array(1, old('hobby'))) ? ' checked' : '' }}> football
</label>
//@sujay
Posted by: Guest on October-20-2020
0

laravel checkbox checked

//You should write a value in the checkbox and then check if that value is null or not:

//HTML, in form:
<input id="check" type="checkbox" name="check" value="check">

//PHP, in controller:
$isChecked = $request->check != null;

//If the checkbox is checked, then the $request->check will not be null. Otherwise, it will.
//Then the $isChecked variable will be true if the checkbox is checked, and false if it isn't.
Posted by: Guest on December-18-2021

Browse Popular Code Answers by Language