0

So, I have this in my edit.blade.php

<div class="form-check disabled">
    <label class="form-check-label">
        <input class="form-check-input" type="hidden" value='0' name="is_default">
        <input class="form-check-input" type="checkbox" value='1' name="is_default">
        Default Variant
    </label>
</div>

and I have an is_default column in my database which has the values of either 0 or 1 depending if the checkbox is checked or not.

Now, I want to create an edit page and I want to show if that if is_default value is 1 then the checkbox should be checked, else it will be unchecked.

the value of is_default is represented as value="{{ $variant->is_default }}"

1 Answer 1

4

Let's try this

In edit.blade.php

<div class="form-check disabled">
<label class="form-check-label">
    <input class="form-check-input" type="checkbox" value='1' name="is_default" {{ (isset($variant->is_default) && !empty($variant->is_default))?'checked':'' }}>
    Default Variant
</label>
</div>

in controller check for

<?php
.....
$is_default = isset($_POST['is_default'])?1:0;
// If checkbox is checked then isset will become true else false
// Update the db
....
?>

I hope this will help you... Happy Coding:)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! Works like charm! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.