Maatwebsite Excel import problem . When i import other value it’s work fine but when i insert date it’s say server error

  laravel, maatwebsite-excel

I try this solution but it does not work
https://github.com/Maatwebsite/Laravel-Excel/issues/1832

only date import problem other data get and import successfully
my import function is given below :

public function collection(Collection $rows)
{



    foreach ($rows as $row)
    {


        $user=new User;
        $user->username=$row['username'];
        $user->first_name=$row['first_name'];
        $user->last_name=$row['last_name'];
        $user->email=$row['email'];
        $user->password=bcrypt($row['password']);
        $user->contact_no=$row['contact_no'];
        $user->role_users_id=2;
        $user->save();
    

        $emp_id=$user->id;
        $employee = new Employee();
        $employee->id=$emp_id;
        $employee->first_name=$row['first_name'];
        $employee->last_name=$row['last_name'];
        $employee->email=$row['email'];
        $employee->contact_no=$row['contact_no'];
        $employee->gender=$row['gender'];
        $employee->address = $row['address'];
        $employee->city = $row['city'];
        $employee->country =$row['country'];
        $employee->zip_code =$row['zip'];
        $employee->role_users_id=2;
        $employee->joining_date=PhpOfficePhpSpreadsheetSharedDate::excelToDateTimeObject('Y-m-d',strtotime($row['date_of_joining']));
        dd($employee);
        //  $employee->joining_date=date('Y-m-d',strtotime($row['joining_date']));
        //  $employee->joining_date=date_format($row['date_of_joining'],"Y-m-d");
        //  $employee->date_of_birth= date('Y-m-d',strtotime($row['date_of_birth']));
        $employee->save();

    }

}

Source: Laravel

Leave a Reply