PHPackages                             team383/data-table-laravel - 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. [Search &amp; Filtering](/categories/search)
4. /
5. team383/data-table-laravel

ActiveLibrary[Search &amp; Filtering](/categories/search)

team383/data-table-laravel
==========================

A Laravel package to facilitate the creation of dynamic data tables for Eloquent models, allowing sorting, searching, filtering and pagination

1.1.2(1y ago)02MITPHPPHP ^8.4

Since Feb 5Pushed 1y agoCompare

[ Source](https://github.com/383Project/data-table-laravel)[ Packagist](https://packagist.org/packages/team383/data-table-laravel)[ Docs](https://github.com/383project/data-table-laravel)[ GitHub Sponsors]()[ RSS](/packages/team383-data-table-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (5)Used By (0)

383's Data Table (Laravel Package)
==================================

[](#383s-data-table-laravel-package)

This package provides a simple way to create the back end for a data table in Laravel. It is designed to work with our [React Data Table](https://github.com/383Project/data-table-react) package, and could later include other front end packages as well.

The purpose of the data table is relatively simple and common; to provide a table of data that can be sorted, filtered, searched and paginated.

This back end portion focusses on providing a good Laravel-esque interface you can use with your Eloquent models in order to provide controllers for your data tables in a uniform way.

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

[](#installation)

You can install the package via composer:

```
composer require SteJaySulli/laravel-react-data-table
```

Data Table Controllers
----------------------

[](#data-table-controllers)

The data table controller is the core of this package. Each data table needs a controller in order to define how the data is retrieved. This package provides a [base data table controller](./src/Http/Controllers/DataTableController.php) that you can extend to create your own data table controllers.

The only feature you **must** provide is the `query` method, which should return a query builder instance that will be used to retrieve the data for the data table, but there are a number of other properties and methods you can override or provide to customise the behaviour of the data table.

Hidden Fields
-------------

[](#hidden-fields)

Sometimes you need data to be available to the front end code, but do not want it to be displayed as a column in the table. You can define hidden fields in your data table controller either by providing a `$hidden_fields` property or, if you require more complex behaviour, by overriding the `getHiddenFields` method.

Field Labels
------------

[](#field-labels)

By default, the field labels will be taken from the field names; these will be have all non-alphanumeric characters converted to single spaces and the string will be converted to title case (for example `my-weird_field&&&name` =&gt; `My Wierd Field Name`). You can override this behaviour by providing a `$field_labels` property or by overriding the `getFieldLabels` method.

It's worth noting that the default implementation of `getFieldLabels` contains the logic which converts any field names missing from the `$field_labels` property to title case, so if you override this method you may want to provide an alternative implementation or you will be at the mercy of the front end's fallback.

Sortable, Searchable and Filterable Fields
------------------------------------------

[](#sortable-searchable-and-filterable-fields)

This package allows you a great deal of control over which fields are sortable, searchable and filterable; let's define what these terms mean:

- Sortable means that the user can click on the column header to sort the data by that column in order to select it for sorting, either in ascending or descending order
- Searchable means that the user can type into a search box to filter the data shown. Searches `OR` the field filters, so records are shown if they match any fields against the given search term
- Filterable means the user can select one or more filters. Filters `AND` the field filters, so records are shown if they match all fields against the given filter options.

Note that by default the search functionality uses a text input, whereas the filters use an array structure

### Sorting

[](#sorting)

In order to make a field sortable, simply add it to the `$sortable_fields` property of the controller; this will work automatically for simple sorting (ie where the corresponding database query is just `ORDER BY field ASC/DESC`), but for more complex queries you will need to provide a sort method.

This is done by creating a method that begins with `sort` followed by the field name of the field in pascal case (making the function name camel case); this method should take two arguments, the query builder and the direction of the sort (either `asc` or `desc`); for example a common case may be where we have concatenated first and last names, but we need to sort against the full name - for this example let's assume we also want to sort by last\_name first as well:

```
    public function sortFullName(Builder $query, string $direction): Builder
    {
        return $query->orderBy('last_name', $direction)->orderBy('first_name', $direction);
    }
```

### Searching

[](#searching)

In order to make a field searchable, simply add it to the `$searchable_fields` property of the controller; this will work automatically for simple searches (ie where the corresponding database query is just `WHERE field LIKE %search_term%`), but for more complex queries you will need to provide a search method.

This is done by creating a method that begins with `search` followed by the field name of the field in pascal case (making the function name camel case); this method should take two arguments, the query builder and the search term; for example a common case may be where we have concatenated first and last names, but we need to search against the full name:

```
    public function searchFullName(Builder $query, string $search_term): Builder
    {
        return $query->whereRaw('CONCAT(first_name, " ", last_name) LIKE ?', ["%$search_term%"]);
    }
```

### Filtering

[](#filtering)

In order to make a field filterable, simply add it to the `$filterable_fields` property of the controller; this will work automatically for simple filters (ie where the corresponding database query is just `WHERE field = filter_value` for a simple string, or `WHERE field IN (values)` where an array is given), but for more complex queries you will need to provide a filter method.

This is done by creating a method that begins with `filter` followed by the field name of the field in pascal case (making the function name camel case); this method should take two arguments, the query builder and the filter value; for example a common case may be where we have a status field that is an integer, but we want to filter against a string representation of a list of statuses:

```
    public function filterStatus(Builder $query, string $statuses): Builder
    {
        return $query->whereIn('status', explode(',', $statuses));
    }
```

When the front end requests filters, this should be provided in a filter array, where the key is the field name and the value is the filter value; for example:

```
{
    "filters": {
        "brand": "Honda"
        "type":[
            "car",
            "motorcycle"
        ],
        "status": "new, used, damaged"
    }
}
```

This example would filter the data to only show records where the brand is Honda, the type is either car or motorcycle, and the status is new, used or damaged (according to the example custom method above)

Resource Classes
----------------

[](#resource-classes)

By default, the controller will use the `DefaultDataTableResource` to format its output, but you can provide a custom resource class by setting the `$resource_class` property or overriding the `getResourceClass` method of the controller.

Whichever resource class you use, the response will have a few properties added to its metadata which are used by the front end:

- `hidden_fields`
- `field_labels`
- `sortable_fields`
- `searchable_fields`
- `filterable_fields`
- `sort`
- `direction`

These properties are used by the front end to determine how to display the data table and what options to provide to the user.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance46

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

3

Last Release

437d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5497bae5ba869e14821b6d8e27e650d014bb5ec227235252376247bb6ca0a638?d=identicon)[Team383](/maintainers/Team383)

---

Top Contributors

[![SteJaySulli](https://avatars.githubusercontent.com/u/60765965?v=4)](https://github.com/SteJaySulli "SteJaySulli (7 commits)")[![JMidoro](https://avatars.githubusercontent.com/u/99602589?v=4)](https://github.com/JMidoro "JMidoro (5 commits)")

---

Tags

laraveldata-table-laravel383project

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/team383-data-table-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/team383-data-table-laravel/health.svg)](https://phpackages.com/packages/team383-data-table-laravel)
```

###  Alternatives

[spatie/laravel-site-search

A site search engine

300129.1k](/packages/spatie-laravel-site-search)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[codewithdennis/filament-price-filter

A simple and customizable price filter for FilamentPHP, allowing users to easily refine results based on specified price ranges.

163.2k](/packages/codewithdennis-filament-price-filter)[eightynine/filament-docs

Elegant documentation system for your Filament application with search, navigation, and markdown support

122.5k1](/packages/eightynine-filament-docs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
