Events
Tapix dispatches events at key points during the import lifecycle. You can listen to these events to trigger notifications, log activity, update dashboards, or perform any custom logic.
Available Events
use Tapix\Core\Events\ImportStarted;
use Tapix\Core\Events\ImportRowProcessed;
use Tapix\Core\Events\ImportCompleted;
use Tapix\Core\Events\ImportFailed;
ImportStarted
Dispatched when ExecuteImportJob begins processing an import.
| Property | Type | Description |
|---|---|---|
$import | Import | The import model instance. |
ImportRowProcessed
Dispatched after each chunk of rows is processed during ExecuteImportJob. Use this event for real-time progress tracking.
| Property | Type | Description |
|---|---|---|
$import | Import | The import model instance. |
$processedCount | int | Number of rows processed so far. |
$totalCount | int | Total number of rows in the import. |
ImportCompleted
Dispatched when the import finishes successfully with all rows processed.
| Property | Type | Description |
|---|---|---|
$import | Import | The import model instance. |
ImportFailed
Dispatched when the import fails due to an unrecoverable exception.
| Property | Type | Description |
|---|---|---|
$import | Import | The import model instance. |
Listener Example
Create a listener to respond to import completion:
use Tapix\Core\Events\ImportCompleted;
class SendImportReport
{
public function handle(ImportCompleted $event): void
{
$import = $event->import;
logger()->info("Import completed", [
'id' => $import->id,
'created' => $import->created_rows,
'updated' => $import->updated_rows,
'skipped' => $import->skipped_rows,
'failed' => $import->failed_rows,
]);
}
}
Register the listener in your EventServiceProvider or use Laravel's automatic event discovery.
Progress Tracking
The ImportRowProcessed event enables real-time progress tracking. Since it fires after each chunk, you can calculate the percentage and broadcast updates to the frontend:
use Tapix\Core\Events\ImportRowProcessed;
class TrackImportProgress
{
public function handle(ImportRowProcessed $event): void
{
$percentage = ($event->processedCount / $event->totalCount) * 100;
broadcast(new ImportProgressUpdated(
importId: $event->import->id,
percentage: round($percentage, 1),
processed: $event->processedCount,
total: $event->totalCount,
));
}
}
This pairs well with a frontend component that listens for broadcast events to display a live progress bar during import execution.