mercredi 23 septembre 2020

Laravel: How to save checkbox value

I get this error, when I submit the form

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'onloan' cannot be null

Please help. Sorry for the noob question. I've been searching but the examples are different.

edit.blade.php

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

controller

    public function update(Request $request, Item $item)
    {
        $item->update([
            'name' => $request->name,
            'description' => $request->description,
            'barcode' => $request->barcode,
            'onloan' => $request->onloan //Not Working
        ]);
    }



Aucun commentaire:

Enregistrer un commentaire