Download the PHP package genesis-brain/laravel-excel-import-analysis without Composer
On this page you can find all versions of the php package genesis-brain/laravel-excel-import-analysis. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download genesis-brain/laravel-excel-import-analysis
More information about genesis-brain/laravel-excel-import-analysis
Files in genesis-brain/laravel-excel-import-analysis
Package laravel-excel-import-analysis
Short Description A reusable Excel import analysis framework for Laravel with rules, severity levels, analysis DTOs, and modular import behavior.
License MIT
Informations about the package laravel-excel-import-analysis
Genesis Brain Laravel Excel Imports Analysis
A reusable, rule-based Excel import analysis framework for Laravel. It provides structured per-row analysis, severity levels, contextual DTOs, and a clean import architecture that integrates seamlessly with Laravel Excel.
This package is designed to help you build robust, extensible, and maintainable Excel import pipelines in your Laravel applications.
β¨ Features
- π§© Rule-based per-row validation
- β οΈ Built-in severity levels (
INFO,WARNING,ERROR,CRITICAL) - π Rich DTOs (messages, codes, row/column/cell, context)
- π Pluggable rules via repository
- β»οΈ Reusable import architecture using traits & contracts
- π Clean interfaces and abstract base classes
- π Fully compatible with Maatwebsite/Laravel-Excel
π¦ Installation
Requires:
- PHP >= 8.3
- Laravel >= 12
- maatwebsite/excel >= 4.0
π Basic Usage
1. Create an Import
2. Run the Import
If any analysis results are produced at or above the configured minimal level, an
Gbrain\ExcelImports\Exceptions\ExcelImportNotPassedRulesValidation exception
will be thrown. You can catch it to surface errors to users or logs.
π Controlling Analysis Execution: withAnalysis() and withoutAnalysis()
The AnalyzesData trait provides two important methods to control when analysis rules run during an import:
β
withAnalysis(bool $withoutImport = false) (default behaviour)
Enables analysis and allows you to decide whether the import should also run.
Since $onlyAnalysis is false by default, calling withAnalysis() without arguments means:
β‘ Analysis runs β‘ Import also runs (if analysis passes)
You may optionally pass a boolean:
withAnalysis(false)β normal mode: validate rows and import if validwithAnalysis(true)β analysis-only mode: validate rows, skip import entirely
Example (normal mode):
- Each row is validated using your registered rules
- All analysis results are collected
- If any rule produces a result at or above the minimal report level, an exception is thrown
β withoutAnalysis()
Disables all rule checks.
Use this when you want to:
- Import data without validation
- Re-run an import using only the business logic (
handleRowImport()) - Bypass rules temporarily (e.g. admin override)
Example:
π How it works internally
withAnalysis() and withoutAnalysis() work together using two internal flags:
$analyzeBeforeHandleβ whether rules should run at all$onlyAnalysisβ whether only rules should run (skipping import)
According to the current implementation:
β Default state
$analyzeBeforeHandle = true$onlyAnalysis = false
So calling withAnalysis() with no arguments:
- enables analysis
- does NOT skip import
β Truth table
| Method call | $analyzeBeforeHandle |
$onlyAnalysis |
Effect |
|---|---|---|---|
withAnalysis() |
true |
false |
Run analysis and then import |
withAnalysis(false) |
true |
false |
Same as above |
withAnalysis(true) |
true |
true |
Run analysis only, no import |
withoutAnalysis() |
false |
false |
Skip analysis, run import only |
β What actually happens
- If analysis is enabled (
$analyzeBeforeHandle = true), rules run on each row. - If minimal report level is breached, an exception is thrown.
- If only analysis is enabled (
$onlyAnalysis = true), the import is skipped entirely. - If withoutAnalysis() is called, rules are skipped and only import logic runs.
Summary
- withAnalysis() β analysis + import (default)
- withAnalysis(true) β analysis only
- withAnalysis(false) β analysis + import
- withoutAnalysis() β import only
This gives you full control over whether to run validation-only scans, full validated imports, or unvalidated imports.**, without changing your import class.
π§ͺ Writing Custom Rules
Rules extend the abstract ExcelImportAnalysisRule and return an
ExcelImportAnalysisResultDto when the rule fails.
Then register it in your importβs getRulesCollection() method.
π Severity Levels
The package ships with a built-in severity enum:
Levels are comparable using helper methods:
Internally, comparison is driven by PHP 8 attributes (ComparableValue) attached
to each enum case.
π§± Architecture Overview
- Contracts β describe import, rule, and repository responsibilities
- Abstracts β provide base behavior (rules, repository)
- Concerns β traits that orchestrate analysis (
AnalyzesData) - Enums β severity levels, with comparable semantics
- DTOs β carry structured analysis results
- Exceptions β encapsulate failed analysis and structured context
π§ͺ Testing
This package is designed to be test-friendly. Example Pest tests:
Run tests with:
π License
MIT