jeudi 30 juillet 2020

Invalid datetime format in laravel while sending data from angular

Can anyone help me how to solve this issue? I have a request data from angular that I had passed to the laravel backend for inserting multiple rows at a time. But I got below error. I tried running the below query in Mysql, it is working fine there but not from laravel.

How can I fix this??

Request data from Angular (API):

[
  {
    "customer_id": 3,
    "check_in_date": "2020-07-30T00:00:00.000Z",
    "check_out_date": "2020-07-31T00:00:00.000Z",
    "room_id": 2
  },
  {
    "customer_id": 3,
    "check_in_date": "2020-07-29T00:00:00.000Z",
    "check_out_date": "2020-07-31T00:00:00.000Z",
    "room_id": 3
  }
]

Migration Table

public function up()
{
    Schema::create('reservations', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->unsignedBigInteger('room_id');
        $table->foreign('room_id')->references('id')->on('rooms');
        $table->unsignedBigInteger('customer_id');
        $table->foreign('customer_id')->references('id')->on('customers');
        $table->unsignedBigInteger('booking_id')->nullable();
        $table->foreign('booking_id')->references('id')->on('bookings');
        $table->dateTime('check_in_date');
        $table->dateTime('check_out_date');
        $table->timestamps();
    });
}

Controller of reservation:

public function store(Request $request)
{
    $reservation = Reservation::insert($request->all());
    
    return $this->jsonResponse(true, 'Reservation has been created successfully.', $reservation);
}


private function jsonResponse($success = false, $message = '', $data = null)
{
    return response()->json([
        'success' => $success,
        'message' => $message,
        'data' => $data
    ]);
}

Error:

 "message": "SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2020-07- 
 29T00:00:00.000Z' for column 'check_in_date' at row 1 

 (SQL: insert into `reservations` (`check_in_date`, `check_out_date`, `customer_id`, `room_id`)

 values (2020-07-30T00:00:00.000Z, 2020-07-31T00:00:00.000Z, 3, 2),
        (2020-07-29T00:00:00.000Z, 2020- 07-31T00:00:00.000Z, 3, 3))",
 "exception": "Illuminate\\Database\\QueryException",


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2XclDBz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire