0

I am able to save checkbox values into my database. When i am fetching, i try to get the selected checkbox as below but nothing is selected.. What could i be doing wrong in my code please ?

View

<ul class="list-unstyled mb-0">
                    @foreach($permission as $value)
                        <li>
                            <label class="fancy-checkbox mb-0">
                                <input type="checkbox" in_array($value->id, $rolePermissions) ? true : false value="{{$value->id}}"  name="permission[]">
                                <span>{{ $value->display_name }}</span>
                                &nbsp;&nbsp;&nbsp; -
                                <span>{{ $value->description }}</span>

                            </label>
                            <hr>
                        </li>
                    @endforeach
                    </ul>

1 Answer 1

1

You're missing the .blade syntax, and you should use 'checked' instead of true : false:

<input type="checkbox" value="{{ $value->id }}" name="permission[]" {{ in_array($value->id, $rolePermissions) ? 'checked' : '' }}/>

For checkboxes, simply setting checked is all that is required to determine if it should be initially checked or not.

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

2 Comments

I just tried with the code above but results is the same..Nothing is selected
If nothing is checked with that code, then it means that in_array() is returning false. What specifically does $rolePermissions contain? (Add the output of dd($rolePermissions); to your question)

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.