Laravel 4 Eloquent assign BIT values

会有一股神秘感。 提交于 2019-12-25 16:56:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!