PHPackages                             fazzinipierluigi/laraccoon\_datasource - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. fazzinipierluigi/laraccoon\_datasource

ActiveLibrary[Database &amp; ORM](/categories/database)

fazzinipierluigi/laraccoon\_datasource
======================================

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

1.0.0(1mo ago)07MITPHP

Since Jun 9Pushed 1mo agoCompare

[ Source](https://github.com/fazzinipierluigi/laraccoon_datasource)[ Packagist](https://packagist.org/packages/fazzinipierluigi/laraccoon_datasource)[ RSS](/packages/fazzinipierluigi-laraccoon-datasource/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Laraccoon Datasource
====================

[](#laraccoon-datasource)

Laravel library that processes server-side requests from the [Raccoon Tables](https://github.com/fazzinipierluigi/raccoon-tables) JavaScript plugin and returns the expected response format.

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

Features
--------

[](#features)

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

Installation
------------

[](#installation)

```
composer require fazzinipierluigi/laraccoon_datasource
```

Basic usage
-----------

[](#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
----------------

[](#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
---------

[](#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
-------------

[](#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
--------------------

[](#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
------------------

[](#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
--------------------------

[](#supported-filter-operators)

`sign`Behavior`=`Contains (LIKE `%value%`)`!=`Not contains`==`Equals exact`!==`Not equals`>`Greater than`
