Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
121 views
in Technique[技术] by (71.8m points)

Laravel: Class 'AppImportsDate' not found

I've imported Excel File to database MySql, but I'dont know why my import display this error "Class 'AppImportsDate' not found".

This is my controller VouchersImport.php:

namespace AppImports;
use AppImportsDate;
use CarbonCarbon;
use AppVouchers;
use MaatwebsiteExcelConcernsToModel;
use MaatwebsiteExcelConcernsWithHeadingRow;
use MaatwebsiteExcelConcernsWithBatchInserts;
use MaatwebsiteExcelConcernsWithChunkReading;
use MaatwebsiteExcelImportsHeadingRowFormatter;

HeadingRowFormatter::default('none');

class VouchersImport implements ToModel, WithHeadingRow, WithBatchInserts, WithChunkReading
{
    /**
    * @param array $row
    *
    * @return IlluminateDatabaseEloquentModel|null
    */

    private function transformDateTime(string $value, string $format = 'Y-m-d')
    {
        try {
                return Carbon::instance(Date::excelToDateTimeObject($value))->format($format);
            } 
            catch (ErrorException $e) 
            {
                return Carbon::createFromFormat($format, $value);
            }
    }

question from:https://stackoverflow.com/questions/65933615/laravel-class-app-imports-date-not-found

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

use use AppImportsDate; to PhpOfficePhpSpreadsheetSharedDate

then it will be

namespace AppImports;
use PhpOfficePhpSpreadsheetSharedDate;
use CarbonCarbon;
use AppVouchers;
use MaatwebsiteExcelConcernsToModel;
use MaatwebsiteExcelConcernsWithHeadingRow;
use MaatwebsiteExcelConcernsWithBatchInserts;
use MaatwebsiteExcelConcernsWithChunkReading;
use MaatwebsiteExcelImportsHeadingRowFormatter;

HeadingRowFormatter::default('none');

class VouchersImport implements ToModel, WithHeadingRow, WithBatchInserts, WithChunkReading
{
    /**
    * @param array $row
    *
    * @return IlluminateDatabaseEloquentModel|null
    */

    private function transformDateTime(string $value, string $format = 'Y-m-d')
    {
        try {
                return Carbon::instance(Date::excelToDateTimeObject($value))->format($format);
            } 
            catch (ErrorException $e) 
            {
                return Carbon::createFromFormat($format, $value);
            }
    }


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...