Core Types and Enums
This reference summarizes the core package types used to define sources, build report definitions, run previews, and export files.
Core classes
Ihasan\ReportBuilder\ReportBuilderregisterDataSource(DataSourceContract $dataSource): voiddataSource(string $key): DataSourceContractdataSources(): array
Ihasan\ReportBuilder\Execution\PreviewRunner- executes a
ReportDefinitionand returns paginated preview output
- executes a
Ihasan\ReportBuilder\Execution\ReportRunner- executes a
ReportDefinitionand returns export payloads
- executes a
Ihasan\ReportBuilder\DataSources\EloquentDataSource- default implementation for model-backed sources
Ihasan\ReportBuilder\Support\Field- fluent builder for
FieldDefinition
- fluent builder for
Contracts
DataSourceContractkey(): string- stable machine key for report definitionslabel(): string- human-readable source labelfields(): array- all allowedFieldDefinitionvaluesfield(string $key): ?FieldDefinition- lookup one field by keyquery(): EloquentBuilder|QueryBuilder- trusted base query for this sourceapplyScope(...): EloquentBuilder|QueryBuilder- apply user/tenant/request scopesauthorize(Request $request): bool- controls source access in your app layer
Core DTOs
ReportDefinition- root object containing
source_key,selected_columns,filters,sorts,output
- root object containing
SelectedColumn- a selected field and optional output label override
FilterConditionandFilterGroup- filter tree with nested
and/orlogic
- filter tree with nested
SortDefinition- field key + direction (
ascordesc)
- field key + direction (
OutputDefinition- output format and optional filename
Column definitions with Field
Each field key is part of your public report-definition contract. column() maps that key to a trusted DB column.
php
Field::decimal('total_amount')
->label('Total Amount')
->column('orders.total_amount')
->sortable()
->groupable()
->filterable([FilterOperator::Equals, FilterOperator::Between])
->aggregates([AggregateFunction::Sum]);Rule of thumb:
- key = report definition contract
- column = backend trusted mapping
- operators/aggregates = allowlist for execution
Execution return contracts
- Preview (
PreviewRunner::preview) returns:columnsrowspagination
- Export (
ReportRunner::export) returns:filenamemime_typecontent
Enums
FieldTypestring,integer,decimal,boolean,date,datetime
FilterOperator=,!=,>,>=,<,<=,like,not_like,starts_with,ends_with,in,not_in,between,not_between,is_null,is_not_null,date_equals,date_before,date_after,this_week,this_month,this_year,last_n_days
AggregateFunctioncount,sum,avg,min,max
Exceptions you will commonly see
DataSourceAlreadyRegisteredExceptionDataSourceNotFoundExceptionInvalidDataSourceConfigurationExceptionInvalidReportDefinitionException