$employee->state_id = $request->state_id ?? null;
null is not a string man.
In a project I am using Angular-12 as frontend and Laravel-8 as backend.
Laravel:
'state_id' => [
'nullable'
],
'city_id' => [
'nullable'
],
$employee = Employee::find($id);
$employee->nationality_id = $request->nationality_id;
$employee->state_id = $request->state_id ?? null;
$employee->city_id = $request->city_id ?? null;
$employee->save();
It is a dependent dropdown. Whenever state_id is not selected I got this error:
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'null' for column
myapp.employees.state_id
Same thing with city_id
Note: state_id and city_id are nullable in the DB.
state_id, city_id are integers. But if there is value in it, it is inserted without any error.
How do I get this resolved?
Thanks
$employee->state_id = $request->state_id ?? null;
null is not a string man.
Please or to participate in this conversation.