I am posting data via insomnia to lumen api and want data to be sent to the database but i am experiencing invalid datetime error
I have tried converting the datetime to mysql format but i have failed, both using Carbon, Casting and strtotime php function like below 1. strtotime($value); 2. Carbon::createFromFormat('Y-m-d H:i:s', $value); 3. Casting the date like this 'parking_end_time' => 'datetime:Y-m-d H:i:s',
$router->group(['prefix' => 'api', 'namespace' => 'API'], function
() use ($router) {
/* Check Ins */
$router->post('checkin', 'CheckInController@store');
/* Payment Status */
$router->get('payments/status', 'PaymentStatusController@index');
/* Vehicle Categories */
$router->get('vehicles/categories',
'VehicleCategoryController@index');
/* Parking Areas */
$router->get('parking/areas', 'ParkingAreaController@index');
/* Parking Types*/
$router->get('parking/types', 'ParkingTypeController@index');
/* Vehicles */
$router->get('vehicles', 'VehicleController@index');
$router->get('vehicles/{vehicleRegistrationNumber}',
'VehicleController@show');
});
// Above are the routes
// Mutator on my model
public function setParkingStartTimeAttribute($value)
{
$this->attributes['parking_start_time'] =
Carbon::createFromFormat($value);
}
// Action in Controller
public function store(Request $request)
{
$this->validateCheckInRequest($request);
$parkingStartTime = Carbon::createFromFormat('Y-m-d H:i:s',
$request->parking_start_time);
return response()->json($parkingStartTime); // for testing purposes when i return this it gives me the result below
$checkIn = CheckIn::create($request->all());
return new CheckInCollection($checkIn);
}
// Result given when i return the parking_start_time
{
"date": "-0001-11-30 21:27:00.000000",
"timezone_type": 3,
"timezone": "UTC"
}
I expected the datetime return to be like this "0000-00-00 21:27:00" but i see this "-0001-11-30 21:27:00.000000"