qirolab / laravel-excel-export-import-example Goto Github PK
View Code? Open in Web Editor NEWLaravel Excel export, import tutorial with example
Home Page: https://qirolab.com
Laravel Excel export, import tutorial with example
Home Page: https://qirolab.com
I am using ShouldQueue method to have the large CSV into Queue but the errors of validations I am not able to catch them!
public function registerEvents(): array { return [ ImportFailed::class => function(ImportFailed $event) { dd($event); // This I will write into the FILE or send EMAIL but the job runs successfully but validation errors keep empty. $this->importedBy->notify(new ImportHasFailedNotification); }, ]; }
My code looks like below...
public function registerEvents(): array { return [ ImportFailed::class => function(ImportFailed $event) { $filename = public_path('tmp').'/validation_error.txt'; $myfile = fopen($filename, "w"); fwrite($myfile, "domo"); fclose($myfile); }, ]; }
I am in hope that if there is any error validation_error.txt file will have "Demo" inside it.
I just wanted to add those errors in a file and email to the user that's it.
Also, I have crossed verify by removing ShouldQueue it gives me proper errors for email already exists a kind of.
Please help if you have any ideas! Thanks!
On failure doesn't skip errors but goes on to add it to the database.
Environment
maatwebsite/excel verrsion:3.1
PHP Version: 8.0
Below is the model
public function rules(): array
{
return [
'cus_name' => 'bail|required|string|max:255',
'cau_cat' => 'required|integer|between:1,4',
'cus_cat' => 'required|integer|between:1,4',
'cus_type' => 'required|integer|between:1,2',
'cus_idnum' => 'required|string|max:255',
'cus_idtype' => 'required|integer|between:1,16',
'cus_type' => 'required|integer|between:1,4',
'listtype_id' =>'required|integer|between:1,4',
'cus_dob' => 'required|date|date_format:Y-m-d',
];
}
public function chunkSize(): int
{
return 1000;
}
public static function afterImport(AfterImport $event)
{
}
public function onFailure(Failure ...$failure)
{
Log::stack(['import-failure-logs'])->info(json_encode($failure));
}
The code in the controller
$file = $request->file('file')->store('import');
$import = new CustomersImport;
$import->import($file);
foreach ($import->failures() as $failure) {
$failure->row(); // row that went wrong
$failure->attribute(); // either heading key (if using heading row concern) or column index
$failure->errors(); // Actual error messages from Laravel validator
$failure->values(); // The values of the row that has failed.
}
if ($import->failures()->isNotEmpty()) {
return back()->withFailures($import->failures());
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.