Skip to content

Start Here

After this page, you can install the package, register one data source, and call the metadata API successfully.

Prerequisites

  • PHP 8.3+
  • Laravel 11, 12, or 13
  • Composer

Step 1: Install the package

bash
composer require ihasan/report-builder
php artisan vendor:publish --tag="report-builder-config"

Step 2: Register your first data source

Add this to your app boot logic (example: AppServiceProvider):

php
<?php

namespace App\Providers;

use App\Models\Order;
use Illuminate\Support\ServiceProvider;
use Ihasan\ReportBuilder\DataSources\EloquentDataSource;
use Ihasan\ReportBuilder\Enums\AggregateFunction;
use Ihasan\ReportBuilder\Enums\FilterOperator;
use Ihasan\ReportBuilder\ReportBuilder;
use Ihasan\ReportBuilder\Support\Field;

class AppServiceProvider extends ServiceProvider
{
    public function boot(ReportBuilder $reportBuilder): void
    {
        $reportBuilder->registerDataSource(
            new EloquentDataSource(
                key: 'orders',
                label: 'Orders',
                model: Order::class,
                fields: [
                    Field::decimal('total_amount')
                        ->label('Total Amount')
                        ->column('orders.total_amount')
                        ->sortable()
                        ->groupable()
                        ->filterable([
                            FilterOperator::Eq,
                            FilterOperator::Between,
                        ])
                        ->aggregates([
                            AggregateFunction::Sum,
                        ]),
                ],
            )
        );
    }
}

Step 3: Verify with API requests

bash
curl http://your-app.test/report-builder/sources
curl http://your-app.test/report-builder/sources/orders

Verify

  • The first endpoint returns a list with orders.
  • The second endpoint returns fields metadata for orders.

Common mistakes

  • Getting 404: check your route_prefix in config/report-builder.php.
  • Empty list: source registration is not running during app boot.
  • Getting 403: your source authorization callback returns false.

Next

Continue with Build Your First Data Source.