there is a bit(1)
type column in database table. but its not working as i expected.
problem is
$invitee = new Invitee();
$invitee->name = "name1";
$invitee->email = "[email protected]";
$invitee->isActive = 0; // "b'0'", '0', false, are also not working
$invitee->save();
I need to put a zero 0
in the isActive
column but its getting value 1
every time when i try to add a record with a 0
.
and i found a question in here.. but the answers are not describing the cause of the problem. glad if someone can explain the issue.
Having bit
type field means that you need to use raw values as a workaround whenever you are inserting/updating that field.
That's because PDO by default will bind these values and they will be treated as strings, thus bit
will result in 1
:
DB::table('table')->insert(['bit_field' => 0]); // inserts 1
DB::table('table')->insert(['bit_field' => DB::raw(0)]); // inserts 0
And I suggest changing it to tinyint
if you could.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With