fazzinipierluigi/laraccoon_datasource

A Laravel library that processes server-side requests from the Raccoon Tables JavaScript plugin and returns the expected response format

Maintainers

Package info

github.com/fazzinipierluigi/laraccoon_datasource

pkg:composer/fazzinipierluigi/laraccoon_datasource

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-06-09 19:25 UTC

This package is auto-updated.

Last update: 2026-06-13 06:49:13 UTC


README

Laravel library that processes server-side requests from the Raccoon Tables JavaScript plugin and returns the expected response format.

Supports Laravel 9, 10, 11, 12, and 13.

Features

  • Filtering (all Raccoon Tables operators)
  • Sorting (multi-sort)
  • Pagination (start / limit)
  • Global search
  • Row grouping with counts and optional aggregations

Installation

composer require fazzinipierluigi/laraccoon_datasource

Basic usage

use Fazzinipierluigi\LaraccoonDatasource\EloquentSource;

public function index(Request $request)
{
    $users = \App\Models\User::where('is_admin', 0);

    $source = new EloquentSource();
    $source->apply($users, $request);
    return $source->getResponse();
}

Method signature

$source->apply(
    $data_set,       // Eloquent\Builder or Query\Builder
    $request,        // Illuminate\Http\Request
    $field_map,      // optional — maps client field index → DB column(s)
    $search_fields,  // optional — field indexes included in globalSearch
    $aggregations    // optional — ['fieldIndex' => 'sum|avg|min|max|count'] for group agValues
);

Field map

Maps the client-side index to one or more DB columns. Useful when the client field name differs from the DB column, or when one grid column maps to multiple DB columns (ORed together for filters).

$field_map = [
    'fiscal_reference' => ['users.tax_code', 'users.vat'], // OR match on both columns
    'creation_date'    => 'created_at',
];

$source->apply($users, $request, $field_map);

Global search

Pass an array of field indexes to search when the globalSearch / search parameter is present. Each field is resolved through $field_map to its DB column(s) and ORed together.

$source->apply($users, $request, $field_map, ['name', 'email', 'fiscal_reference']);

Custom row transform

return $source->getResponse(function ($row) {
    return [
        'username'         => $row->username,
        'fiscal_reference' => $row->is_company ? $row->vat : $row->tax_code,
        'creation_date'    => $row->created_at->format('d/m/Y'),
    ];
});

Group aggregations

When rowGroups is active the response includes a groups map. Pass $aggregations to have the server compute per-group sums/averages.

$source->apply($employees, $request, $field_map, null, [
    'salary' => 'sum',
    'bonus'  => 'sum',
    'age'    => 'avg',
]);

Response:

{
  "data": [...],
  "total": 284,
  "groups": {
    "Engineering": { "amount": 142, "agValues": { "salary": 9230000, "bonus": 1420000, "age": 34.2 } },
    "Marketing":   { "amount": 87,  "agValues": { "salary": 4350000, "bonus": 522000,  "age": 31.7 } }
  }
}

Supported filter operators

sign Behavior
= Contains (LIKE %value%)
!= Not contains
== Equals exact
!== Not equals
> Greater than
< Less than
a_ Starts with
_a Ends with
regex REGEXP (MySQL/MariaDB)
empty IS NULL or empty string
!empty IS NOT NULL and not empty string
+ Numeric >= 0
- Numeric < 0
in whereIn (value must be an array)
T Boolean true
F Boolean false or NULL