mblsolutions / report
Laravel Report package
Requires
- php: ^8.2
- ext-json: *
- doctrine/dbal: ^3.3|^4.0
- illuminate/cache: ^9.0|^10.0|^11.0|^12.0
- illuminate/console: ^9.0|^10.0|^11.0|^12.0
- illuminate/contracts: ^9.0|^10.0|^11.0|^12.0
- illuminate/database: ^9.0|^10.0|^11.0|^12.0
- illuminate/events: ^9.0|^10.0|^11.0|^12.0
- illuminate/filesystem: ^9.0|^10.0|^11.0|^12.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0
- illuminate/queue: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
- laravel/legacy-factories: ^1.2
- lerouse/laravel-repository: ^2.4
- maatwebsite/excel: ^3.1
- psr/simple-cache: ^2.0|^3.0
Requires (Dev)
- mockery/mockery: ~1.0
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0
- phpunit/phpunit: ^9.6|^10.5|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- v6.0.0
- v5.2.10
- v5.2.9
- v5.2.8
- v5.2.7
- v5.2.6
- v5.2.5
- v5.2.4
- v5.2.3
- v5.2.2
- v5.2.1
- v5.2.0
- v5.1.0
- v5.0.0
- v4.x-dev
- v4.3.1
- v4.3.0
- v4.2.0
- v3.x-dev
- v3.2.0
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.1
- v3.0.0
- v2.x-dev
- v2.7.7
- v2.7.6
- v2.7.5
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.4
- v2.6.3
- v2.6.2
- v2.6.0
- v2.5.0
- v2.4.1
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.2
- v2.0.0
- v1.x-dev
- v1.3.0
- v1.2
- v1.1.1
- v1.1.0
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-fix/safe-reporting
- dev-fix/report-parameter-binding
- dev-feature/AB61860
- dev-bug/AB49551
- dev-bugfix/raw-key-on-preview
- dev-feature/laravel-v10-upgrade
This package is auto-updated.
Last update: 2026-11-18 15:48:29 UTC
README
Import Laravel Reporting into any Laravel 6+ application using this package.
Installation
Install Laravel Report with composer.
php composer require mblsolutions/report
Copy the package config to your local config.
php artisan vendor:publish --tag=report-config
Copy the package database migrations.
php artisan vendor:publish --tag=report-migrations
Laravel Report comes with its own database migrations, once the package has been installed run the migrations.
php artisan migrate
Upgrading to 6.0
6.0 changes who can run reports and adds limits. Read this before you update.
Breaking changes
- Inactive reports give 404 on every single-report route and don't run from a schedule or queue.
- Admin checks need the user model to implement
IsAuthenticatableAnAdmin. Without it, every user is a non-admin. - Non-admins can only run reports that carry a middleware listed in
tenant_middleware. An empty list means no non-admin runs. - Runs whose saved user can't be loaded fail.
- Signed export links need the signed-in user named in the link. Guests get 401, other users 403. If your frontend opens the link in a new tab, that tab must be signed in to the app that serves the link; otherwise download the file through your backend or use the queued export.
- Reports run only on
allowed_connections(default: the app's default connection). - MySQL per-query timeouts: 60 s on screen and direct exports, 300 s queued.
- On-screen pages and direct CSV, JSON and Print exports stop at 50,000 rows (422; use the queued export).
- More than 5 pending queued jobs per user gives 429.
- Report editing (manage store, update, destroy and test) is off unless
management_enabledis true. - Schedules:
report:scheduledoes nothing untilschedules.enabledis true. Create and update are admin-only.recipients,frequencyandparametersare validated. render()has norawSQL for non-admins. Job details hide SQL and error text from non-admins.- Select field columns must be in
select_columns(on save, for options and for labels). A chosen value's label comes only from the model'soptions(), as the runner sees them; other values are shown as sent. - Export file links last 3 days. Jobs older than 28 days give 410.
- Direct CSV exports are quoted. In direct CSV and queued exports, text cells starting with
= + - @, tab or CR get a leading'. - List
limitis at most 100. - Queued report jobs have
$tries = 1. replaceParameter()with a value throws.UnauthorizedExceptionreturns 403.
Apps that override a package controller, job or command don't get the changes made in that class.
New config
The package doesn't merge its config into yours, so every new key has a default in code. Add the keys you want to change to your published config/report.php.
| Key | Env | Default |
|---|---|---|
tenant_middleware |
- | [] (only admins can run reports) |
timeout.screen / timeout.queued |
REPORT_TIMEOUT_SCREEN / REPORT_TIMEOUT_QUEUED |
60 / 300 seconds per query |
max_rows.export |
REPORT_MAX_EXPORT_ROWS |
50,000 (queued exports have no limit) |
allowed_connections |
REPORT_ALLOWED_CONNECTIONS |
the default connection only |
connection |
REPORT_CONNECTION |
null |
max_pending_jobs |
REPORT_MAX_PENDING_JOBS |
5 |
management_enabled |
REPORT_MANAGEMENT_ENABLED |
false |
select_columns |
- | id, uuid, slug, sku, urn, name |
schedules.enabled |
REPORT_SCHEDULES |
false |
schedules.admin_only |
- | true |
schedules.recipient_domains |
REPORT_RECIPIENT_DOMAINS |
[] (any domain) |
link_expiration |
REPORT_LINK_EXPIRATION |
3 days (was 6) |
queued_export_drivers is now also the list of drivers a queued run or schedule may use.
Admins
Make your user model implement IsAuthenticatableAnAdmin:
use MBLSolutions\Report\Interfaces\IsAuthenticatableAnAdmin; class User extends Authenticatable implements IsAuthenticatableAnAdmin { public function isAuthenticatableAnAdmin(): bool { return $this->is_admin; } }
Tenant middleware
A tenant middleware limits a report to the user's own rows. List it in tenant_middleware and add it to each report non-admins should run. For a user with no tenant, throw UnauthorizedException (403) instead of returning the query unchanged.
use Illuminate\Database\Query\Builder; use MBLSolutions\Report\Exceptions\UnauthorizedException; use MBLSolutions\Report\Middleware\ReportMiddleware; class UserAccount extends ReportMiddleware { public function handle(Builder $builder): Builder { if ($this->authenticatable?->account_id === null) { throw new UnauthorizedException('You must belong to an account to view this report.'); } return $builder->where('orders.account_id', '=', $this->authenticatable->account_id); } }
'tenant_middleware' => [ \App\Report\Middleware\UserAccount::class, ],
A middleware's field() method can hide a report field from a user. The package then also skips the name lookup for that field's value.
Usage
Once the package has been required into your project you can configure which parts of the package you would like to use.
Routes
To enable the package json api routes in your application add the following to your routes file.
Report::routes();
Manage routes
To configure custom middleware/guards around report management/creation only routes.
Report::manageRoutes();
View Routes
To configure custom middleware/guards around report view only routes.
Report::viewRoutes();
Export Routes
To configure custom middleware/guards around report export result only routes.
Report::exportRoutes();
Applying Custom Middleware/Gates
To apply middleware to the routes, wrap the routes in middleware groups.
Route::middleware(['admin'])->group(function () { Report::manageRoutes(); }); Route::middleware(['user'])->group(function () { Report::viewRoutes(); }); Route::middleware(['web'])->group(function () { Report::exportRoutes(); });
To apply gates to the routes, wrap the routes in middleware groups.
Route::middleware(['can:manage-reports'])->group(function () { Report::manageRoutes(); }); Route::middleware(['can:view-reports'])->group(function () { Report::viewRoutes(); });
Report Select Parameter Models
To enable select options when creating/rendering reports, you must add the available model types to be reported on in the
report.php config file. Any models added to this array will be available when creating new report fields.
Models added to the array should implement the \MBLSolutions\Report\Interfaces\PopulatesReportOption interface
options($value, $name) must return items keyed by the field's value and name columns. The label shown for a chosen
value comes from the same list, so scope it to the signed-in user (auth()->user()). Queued and scheduled runs sign in
the job owner while options() runs.
Please Note: We recommend that large record sets are not used as select types, due to usability/browser performance issues.
[
'models' => [
\App\User::class,
\App\Order::class
]
]
Scheduled Reporting
To enable scheduled reporting add the following line into the schedule method of the \App\Console\Kernel file of your
laravel application.
$schedule->command(\MBLSolutions\Report\Console\Commands\DispatchScheduledReportsCommand::class)->hourly();
Schedules only run when REPORT_SCHEDULES=true.
Report JSON API
The following endpoints are available to you once the routes have been added:
View Routes (synchronous)
| Method | URI | Name |
|---|---|---|
| GET | /api/report | report.index |
| GET | /api/report/{report} | report.show |
| POST | /api/report/{report} | report.render |
| POST | /report/{report}/export | report.export |
| GET | /api/report/connection | report.connection.list |
| GET | /api/report/middleware | report.middleware.list |
| GET | /api/report/data/type | report.data.type.list |
| GET | /api/report/model | report.model.list |
Queued View Routes (asynchronous)
| Method | URI | Name |
|---|---|---|
| GET | /api/report/queue | report.queue.index |
| GET | /api/report/queue/pending | report.queue.pending.index |
| POST | /api/report/queue/{report} | report.queue.render |
| GET | /api/report/queue/job/{job} | report.queue.job |
| GET | /api/report/queue/result/{job} | report.queue.result |
| GET | /api/report/queue/export/{job} | report.queue.export |
Scheduled Report Routes
| Method | URI | Name |
|---|---|---|
| GET | /report/schedule/frequency | report.schedule.frequencies |
| GET | /report/schedule | report.schedule.index |
| POST | /report/schedule | report.schedule.create |
| GET | /report/schedule{schedule} | report.schedule.show |
| PATCH | /report/schedule/{schedule} | report.schedule.create |
| DELETE | /report/schedule/{schedule} | report.schedule.destroy |
Export Routes
| Method | URI | Name |
|---|---|---|
| GET | /report/{report}/export | report.export |
Manage Routes
| Method | URI | Name |
|---|---|---|
| GET | /api/report/manage | report.manage.index |
| POST | /api/report/manage | report.manage.store |
| POST | /api/report/test | report.manage.test |
| GET | /api/report/manage/{report} | report.manage.show |
| PATCH | /api/report/manage/{report} | report.manage.update |
| DELETE | /api/report/manage/{report} | report.manage.destroy |
| DELETE | /api/report/manage/settings | report.manage.settings |
Report Events
Events are fired at critical points during report creation/completion
ReportRendered and ReportExported also carry authenticatableId, parameters (without the export link keys) and rows.
| Event | Description | Data | Namespace |
|---|---|---|---|
| ReportCreated | A new report was created. | Report $report | MBLSolutions\Report\Events\ReportCreated |
| ReportUpdated | A report was updated. | Report $report | MBLSolutions\Report\Events\ReportUpdated |
| ReportDestroyed | A report was deleted. | Report $report | MBLSolutions\Report\Events\ReportDestroyed |
| ReportRendered | A report was rendered. | Report $report | MBLSolutions\Report\Events\ReportRendered |
| ReportExported | A report was exported. | Report $report | MBLSolutions\Report\Events\ReportExported |
| ReportRenderStarted | A queued report job to render was started. | Report $report, ReportJob $job | MBLSolutions\Report\Events\ReportRenderStarted |
| ReportChunkComplete | A queued report job chunk was completed. | Report $report, ReportJob $job | MBLSolutions\Report\Events\ReportChunkComplete |
| ReportRenderComplete | A queued report job render was completed. | Report $report, ReportJob $job | MBLSolutions\Report\Events\ReportRenderComplete |
| ScheduledReportDispatched | A scheduled report was run. | ScheduledReport $schedule | MBLSolutions\Report\Events\ReportRenderComplete |