samedi 5 décembre 2015

Laravel 5 checkbox not saving to database

I have the following check box in my form. The form uses from model binding:

 {!! Form::model($user, ['method' => 'PATCH', 'action' => ['AccountController@update']]) !!}
       {!! Form::hidden('text_only_email', 'false') !!}
       <div class="checkbox">
            <label>
                  {!! Form::checkbox('text_only_email', 'true') !!} I'd prefer to receive emails as text only
            </label>
      </div>
      <button type="submit" class="btn btn-primary ">Update</button>
  {!! Form::close() !!}

My controller action is as follows:

 public function update(AccountRequest $request)
 {

       Auth::user()->update($request->all());

       flash()->success('Details updated');

       return redirect('account');
 }

In my user model I have set this as a mass assignment field as well:

protected $fillable = ['first_name', 'last_name', 'text_only_email'];

But when I submit, it's not saving? If I try a similar form to save the the first_name or last_name it seems to update. Why aren't the checkboxes saving then?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire