Seeding a table with boolean value, 1 or 'true'

Published 6 months ago by Gabotronix

Given an user model/table with a boolean value of is_Super_Admin, how should I assign the value? should I use 1 or true? do I have to use commas like this ('true') if so?

public function run()
            'name' => 'Gabotronix',
            'email' => '[email protected]',
            'password' => bcrypt('perolaperra2203'),
            'is_Super_Admin' => true,
6 months ago (699,130 XP)

In my opinion, it should be a boolean true (no quotation marks), because it says what it means. If you use 1 then it could be misinterpreted, or at the very least take a moment to understand.


That depends (for me at least).

If you insert directly to the table i would use 1, as that's the value that get's stored anyway.

If you use models instead, i would use true, cause that's the value that is stored in the model.

That's a matter of taste.


If using 'true' (with quotation marks) it will considered string. While using boolean data type you can use: true, false, 1, 0, '1' or '0'.


'true' would be also true, but please don't do this, cause 'false' !== false. confusing? yes :D

6 months ago (699,130 XP)

This is why I always lean towards true and false as boolean values, their intent in unambiguous.


If your database is MySQL you're better off making the column a tinyint column in the migration as that is what MySQL uses for a "boolean" column anyways, and setting the value with either 1 (true), or 0 (false) as that is what MySQL is going to return to you when you try to retrieve data from a "boolean" column anyways.

6 months ago (252,680 XP)

I use tinyint and store a 0 or 1 but let null be okay if not used. But I normally use for a checkbox.


For a Is_super_admin column the default value should be false in all case, not null. It will spare you some bad surprise.

Please sign in or create an account to participate in this conversation.