Wutame
Wutame

Reputation: 69

Laravel: How to set value of Checkbox from database

The checkbox does not take the value from the database. Help please. Thank you.

edit.blade.php

<div class="form-group">
  <input type="checkbox" class="" id="onloan" 
         value="{{ $item->onloan }}">
  <label for="onloan">On Loan</label>
</div>

Upvotes: 0

Views: 92

Answers (2)

GhanuBha
GhanuBha

Reputation: 1

You have to use checked property to check of input checkbox element.

<input type="checkbox" class="" id="onloan" value="1" {{ $item->onloan == 1 ? 'checked' : '' }}>

Upvotes: 2

Arjun bhati
Arjun bhati

Reputation: 306

<div class="form-group">
    <input type="checkbox" class="" id="onloan" value="{{ $item->onloan }}" {{$item->onloan == 1 ? 'checked' : ''}}>
    <label for="onloan">On Loan</label>
</div>

Upvotes: 0

Related Questions