I'm trying to import data from excel file to database using maatwebsite excel package,
I'm using the following code :
namespace App\Imports;
use Maatwebsite\Excel\Facades\Excel;
use PhpOffice\PhpSpreadsheet\Spreadsheet\Shared\Date;
use App\Models\Casting;
use Carbon\Carbon;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\ToCollection;
use Illuminate\Validation\Rule;
use Maatwebsite\Excel\Concerns\WithValidation;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Auth;
class ProjectsImport implements ToModel,WithHeadingRow,WithValidation
{
use Importable;
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
$casting = new Casting();
$casting->date_naissance = Date::excelToTimestamp($row['date_naissance']);
}
}
But doens't work , I get the following error :
"message": "Class 'PhpOffice\\PhpSpreadsheet\\Spreadsheet\\Shared\\Date' not found",
If you have any idea please help !
