问题
I want to set a filed with BIT
data type in mySql using Eloquent.
$i = new Step;
$i->active = 'b0';
$i->save();
But the active
filed is 1
, I also tried:
$i->active = "b'0'";
$i->active = '0';
$i->active = false;
...
Simply I want to run something like this:
INSERT INTO `steps` (`active`) VALUES (b'0')
回答1:
Talking about active
field:
If you want to use active
and inactive
for flagging active
and inactive
state of any record (i.e. user model) then you may use tinyint
data type.
Bool, Boolean: These types are synonyms for TINYINT(1). A value of zero is considered false. Non-zero values are considered true.
Soft Deleting
Also, Laravel provides built-in mechanism for this kind of operation using a deleted_at
field in the table which is known as soft delete. Read more on the manual link given here, it's easy to implement and use.
来源:https://stackoverflow.com/questions/21799952/laravel-4-eloquent-assign-bit-values