mardi 1 novembre 2022

Why my excel import date format is not working in laravel

I try to import the excel data file but my date format is not working. other than that data import is working file only issue is in the date format Please help to solve this issue.

enter image description here

this is my import code.

<?php

namespace App\Imports;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Carbon;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

use App\student_import;

use App\centres;
use App\Course;

class ImportStudent implements ToModel,WithHeadingRow
{
    /**
    * @param Collection $collection
    */

    public function model(array $row)
    {
        $rowNumber = array_values($row);

        $insert_data[] = array(
            'stud_dob' => Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($rowNumber[8])),
            'stud_gender' => $rowNumber[9],
            'stud_add1' => $rowNumber[10],
            'stud_nationality' => $rowNumber[13],
            'stud_registration_date' => Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($rowNumber[14])),
            'stud_completion_date' => Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($rowNumber[15])),
            'stud_course_status' => $rowNumber[16]
        );

    }
}

This is the error I'm getting when import the data file

enter image description here

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire