I need to show the radio button checked based on database value and update the value if i change the selection of radio button and showed on form.
<label class="radio-inline">
<input type="radio" id="option1" name="status" value="{{ old('is_active', $site->is_active) }}" name="status" >OFF</label>
<label class="radio-inline">
<input type="radio" id="option2" name="status" value="{{ old('is_active', $site->is_active) }}" name="status">ON</label>
this is inside my controller
$site->update([
'name'=>$request['name'],
'copyright'=> $request['copyright'],
'is_active'=>$request['status'] == 'true' ? 1 : 0,
'message'=>$request['message'],
'datatime'=>date('Y-m-d', strtotime($request['datatime'])),
'url'=>$request['url'],
'metadata'=>$request['metadata']
]);
1) NO need two name attribute.
2) you can use {{ ($site->is_active=="0")? "checked" : "" }}
to checked based on database value .
<input type="radio" id="option1" name="status" value="0" {{ ($site->is_active=="0")? "checked" : "" }} >OFF</label>
<input type="radio" id="option2" name="status" value="1" {{ ($site->is_active=="1")? "checked" : "" }} >ON</label>
3) for select box do like this
<selec name="xx" >
<option value="1" {{ ($site->select_values=="1")? "selected" : "" }} ></option>
.
.
</select>
Controller :
$site->update([
'name'=>$request['name'],
'copyright'=> $request['copyright'],
'is_active'=>$request['status'], // == 'true' ? 1 : 0
'message'=>$request['message'],
'datatime'=>date('Y-m-d', strtotime($request['datatime'])),
'url'=>$request['url'],
'metadata'=>$request['metadata']
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With