At the moment I'm using
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('test_binary', function (Blueprint $table) {
$table->increments('id');
$table->char('binary_number', 32)->charset('binary'); // From: https://stackoverflow.com/a/62615777/5675325
$table->timestamps();
});
}
to store 32-bit binary numbers like 00000000000000000000000000000010
which are result of
$binaryString = str_pad(base_convert(2, 10, 2),32,'0',STR_PAD_LEFT);
and are stored in such table
The seeder has something like
'binary_number' => str_pad(base_convert(2, 10, 2),32,'0',STR_PAD_LEFT),
In relation to have a BINARY
type in the DB (as the previous image show), apokryfos suggested
I think bit is what you need here, though I'm not fully sure that Laravel supports that so you might need to use
DB::raw("b'000000010'")
to insert data to bit columns
Jarek Tkaczyk agrees with the (I'm not fully sure that Laravel supports that
) part
Having bit type field means that you need to use raw values as a workaround whenever you are inserting/updating that field. (...)
DB::table('table')->insert(['bit_field' => DB::raw(0)]); // inserts 0
and he suggests for the OP to change to tinyint if he could (for a case of a column that can have as value 0 or 1).
This might hint that if one wants to deal with bit of size 32 through Laravel migrations, one would want to use an integer of higher size than tinyint.
So, if I wanted to have an int with size 32, Alexey Mezenin points out
You can't do this, but you can use different types of integer:
$table->bigInteger() $table->mediumInteger() $table->integer() $table->smallInteger() $table->tinyInteger()
What should happen to
$table->char('binary_number', 32)->charset('binary');
then to accomodate the 32-bit binary numbers as values and how to insert/retrieve such records?