I'm trying to safe some data in my database and get the following error:
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'nsfw' at row 1
The nsfw column has a 0 as a standart value. Thats my table:
The nsfw column is also in the models $fillable array.
I want to detect if a checkbox is checked. If it is checked, nsfw should be 1. If it's not, nsfw should be 0.
Thats the checkbox HTML code:
<div class="form-group">
<label for="nsfw" class="control-label">NSFW</label>
<br>
<input type="checkbox" name="nsfw">
</div>
And thats the controller code:
if (Input::get('nsfw')) {
$nsfw = true;
} else {
$nsfw = false;
}
// dd($nsfw) gives me true or
//false back, depending if the checkbox is checked or not
$thread = new Thread();
$thread->name = Input::get('thread-name');
$thread->description = Input::get('thread-desc');
$thread->age_min = Input::get('thread-min-age');
$thread->age_max = Input::get('thread-max-age');
if ($nsfw == true) {
$thread->nsfw = 1;
} else {
$thread->nsfw = 0;
}
$thread->save();
Thanks for your help and sorry for my bad english!
Aucun commentaire:
Enregistrer un commentaire