I'm having a issue with boolean fields with mysql, I've a migration set like this
Schema::create('clients', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('phone');
$table->boolean('has_whatsapp')->default(0);
$table->timestamps();
});
Since mysql uses tinyint as field type I tried using $table->tinyInteger() without success.
My ClientsController has a method to store, my model has the guarded fields set and it woks with all requests except from this one that come from a checkbox.
The store method looks like this
Client::create([
'name' => request('name'),
'phone' => request('phone'),
'has_whatsapp' => request('has_whatsapp')
]);
and my checkbox in the form looks like this
<div class="control">
<label class="checkbox" for="has_whatsapp">
<input type="checkbox" name="has_whatsapp" id="has_whatsapp"> Whatsapp?
</label>
</div>
I receive this message when I try to store the data with the checkbox checked "SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'on' for column 'has_whatsapp' at row 1 (SQL: insert into 'clients' ('has_whatsapp', 'name', 'phone'..., and I leave it unchecked it try to store the field as null even with the default value set as 0.
If I use sqlite as db everthing works fine, but I need it working with mysql.
What I'm doing wrong? Or the mysql just don't handle booleans well?