Skip to content

Commit a4e7497

Browse files
Update queued.md
1 parent 459f91c commit a4e7497

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

3.1/imports/queued.md

+31
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,37 @@ When `ShouldQueue` is used, the import will automatically be queued.
6262
Excel::import(new UsersImport, 'users.xlsx');
6363
```
6464

65+
## Handling failures in queued imports
66+
67+
When queuing imports you might want a way to handle failed imports. You can do this by using the `ImportFailed` event.
68+
69+
```php
70+
namespace App\Imports;
71+
72+
use App\User;
73+
use Maatwebsite\Excel\Concerns\ToModel;
74+
use Maatwebsite\Excel\Concerns\WithEvents;
75+
use Illuminate\Contracts\Queue\ShouldQueue;
76+
use Maatwebsite\Excel\Concerns\WithChunkReading;
77+
78+
class UsersImport implements ToModel, WithChunkReading, ShouldQueue, WithEvents
79+
{
80+
public function __construct(User $importedBy)
81+
{
82+
$this->importedBy = $importedBy;
83+
}
84+
85+
public function registerEvents(): array
86+
{
87+
return [
88+
ImportFailed::class => function(ImportFailed $event) {
89+
$this->importedBy->notifiy(new ImportHasFailedNotification);
90+
},
91+
];
92+
}
93+
}
94+
```
95+
6596
## Appending jobs
6697

6798
When queuing an import an instance of Laravel's `PendingDispatch` is returned. This means you can chain extra jobs that will be added to the end of the queue and only executed if all import jobs are correctly executed.

0 commit comments

Comments
 (0)