I receive data from a API request and it contains a value "true" or "false".
Before I've used PDO::PARAM_BOOL to bind the value and insert it into MySQL
Now I'm using Laravel and I want to know how I can insert this value as boolean value 1 or 0.
I've created a migration which contains
$table->boolean('businessorder');
I save the data in an array and insert it in my table:
$orderarray = [];
foreach($csv as $data => $orderdata){
$orderarray[] = [
...
'businessorder' => $orderdata['is-business-order'],
...
];
}
I receive the following error
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'false' for column 1
The error message also shows the data to insert in the database as "false" not as 0.
How can I make sure it will insert 0 or 1 instead of true or false
When I do
'businessorder' => (bool)$orderdata['is-business-order'],
It will set everything to 1 (because (bool)'false' is true)