I am experiencing an issue in my create function,
SQLSTATE[HY000]: General error: 1364 Field 'grandtotal' doesn't have a default value (HY000)
upon digging I learned that I need to remove the comma from the value, in my case, in grandtotal and cost they're both decimal.
from this question How to format to decimal number that include comma and dot in laravel?, the answer suggested this code.
$input = '10,000.1111';
$model->column = (float) str_replace(',', '', $input);
$model->save()
my question is how can I apply it to current code?
Here's my store function
$orders = Orders::create($request->only(
'user_id',
'status_id',
'currency_id',
'company_id',
'purchase_no',
'notes',
'delivery_date',
'grandtotal', '=>' , (float) str_replace(',', '', 'grandtotal'),
'publish'
));
$input = $request->all();
for($i=0; $i<= count($input['quantity']); $i++) {
if(empty($input['quantity'][$i]) || !is_numeric($input['quantity'][$i])) continue;
$items = [
'product_id' => $input['product_id'][$i],
'product_code' => $input['product_code'][$i],
'name' => $input['name'],
// 'cost' => $input['cost'][$i],
'cost' => (float) str_replace(',', '', $input['cost'][$i]),
'quantity' => intval($input['quantity'][$i]),
];
Order::create($items);
}
return redirect(route('orders.index'));