PHPackages                             shoboske/laravel-data-table-query-builder - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. shoboske/laravel-data-table-query-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

shoboske/laravel-data-table-query-builder
=========================================

A package for managing the backend of a datatable request, sorting, order, serverside pagination

0166PHPCI passing

Since Jul 3Pushed 1mo agoCompare

[ Source](https://github.com/shoboske/laravel-datatable-query-builder)[ Packagist](https://packagist.org/packages/shoboske/laravel-data-table-query-builder)[ RSS](/packages/shoboske-laravel-data-table-query-builder/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

A package for managing datatable queries with sorting, filtering, and server-side pagination
============================================================================================

[](#a-package-for-managing-datatable-queries-with-sorting-filtering-and-server-side-pagination)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4054dbe075d932212bd8af0a847dcd5090131e35a285b7e9cb99c1470005fb48/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73686f626f736b652f6c61726176656c2d646174612d7461626c652d71756572792d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shoboske/laravel-data-table-query-builder)[![GitHub Tests Action Status](https://github.com/shoboske/laravel-data-table-query-builder/actions/workflows/run-tests.yml/badge.svg)](https://github.com/shoboske/laravel-data-table-query-builder/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://github.com/shoboske/laravel-data-table-query-builder/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/shoboske/laravel-data-table-query-builder/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/0c6d8c4662caf9fe5f8a54006aa49e1d625b05fe6e685b721cd0f1a969a12fce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73686f626f736b652f6c61726176656c2d646174612d7461626c652d71756572792d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shoboske/laravel-data-table-query-builder)

This package adds a reusable Eloquent scope for building datatable queries. It supports selecting searchable columns, applying relationship-aware filtering, ordering by a requested column, and eager-loading relationships used by your datatable.

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

[](#installation)

You can install the package via composer:

```
composer require shoboske/laravel-data-table-query-builder
```

You can publish the config file with:

```
php artisan vendor:publish --tag="data-table-query-builder-config"
```

This is the contents of the published config file:

```
return [
	// SQL operator used when filtering searchable columns.
    'like_term' => 'like',

    // Default sort direction when no explicit direction is provided.
    'default_sort_direction' => 'asc',

    'models' => [
        // Attribute name used to mark columns as searchable in a model.
        'search_term' => 'searchable',
        // Attribute name used when a column should be selected under an alias.
        'alias' => 'alias',
        // Default column used when no sort column is supplied.
        'default_sort_column_name' => 'id',
    ],
    'query_params' => [
        // Query parameter that controls how many records are returned.
        'take' => 'take',
        // Default number of records to return when the take parameter is missing.
        'default_take' => 10,
        // Query parameter that controls how many records are skipped.
        'skip' => 'skip',
        // Query parameter that contains the search term.
        'search' => 'search',
        // Query parameter that contains the column to sort by.
        'sort' => 'sort',
        // Query parameter that contains the sort direction.
        'direction' => 'direction',
    ],
    'response_keys' => [
        // Response key that contains the paginated data.
        'data' => 'data',
        // Response key that contains the total result count.
        'count' => 'count',
    ],
];
```

Usage
-----

[](#usage)

Add the `DataTableQueryBuilderTrait` to your model and define the two required methods.

```
use Illuminate\Database\Eloquent\Model;
use Shoboske\DataTableQueryBuilder\Traits\DataTableQueryBuilderTrait;

class User extends Model
{
	use DataTableQueryBuilderTrait;

	protected function getDataTableColumns(): array
	{
		return [
			'name' => [
				'searchable' => true,
			],
			'email' => [
				'searchable' => true,
			],
		];
	}

	protected function getDataTableRelationships(): array
	{
		return [
            "belongsTo" => [
                "role" => [
                    "model" => 'role_id'
                    'columns' => [
                        'role' => [
                            'searchable' => true,
                            'orderable' => true
                        ]
                    ]
                ]
            ]
        ];
	}
}
```

You can generate those methods automatically with the included command:

```
php artisan data-table:add-trait App\\Models\\User
```

Then use the scope in your controller or query layer:

```
$users = User::query()
	->eloquentQuery('name', 'asc', request('search'))
	->get();
```

If you need to add relationships for sorting or filtering, return them from `getDataTableRelationships()` and pass the relationship names to the scope as the last argument.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Inspiration
-----------

[](#inspiration)

This package was inspired by [James Dordoy's Laravel Vue Datatable package](https://github.com/jamesdordoy/Laravel-Vue-Datatable_Laravel-Package).

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Michael Shobowale](https://github.com/shoboske)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 30% of packages

Maintenance60

Regular maintenance activity

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/58557722?v=4)[Michael Shobowale](/maintainers/shoboske)[@shoboske](https://github.com/shoboske)

---

Top Contributors

[![shoboske](https://avatars.githubusercontent.com/u/58557722?v=4)](https://github.com/shoboske "shoboske (17 commits)")

### Embed Badge

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

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

PHPackages © 2026

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