PHPackages                             lati111/laravel\_dataproviders - 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. [API Development](/categories/api)
4. /
5. lati111/laravel\_dataproviders

ActiveLibrary[API Development](/categories/api)

lati111/laravel\_dataproviders
==============================

A composer package for laravel to create interactable and customizable datatables through api calls

3.3.1(7mo ago)1147MITPHPPHP ^8.2

Since May 16Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/lati111/laravel_dataproviders)[ Packagist](https://packagist.org/packages/lati111/laravel_dataproviders)[ RSS](/packages/lati111-laravel-dataproviders/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (26)Used By (0)

Laravel dataproviders
=====================

[](#laravel-dataproviders)

Adds a base for easy dataprovider manipulation to Laravel. Dataproviders are the API side of a data table, allowing you to search, split by page, sort or filter a model which can then be loaded into a client side table. We recommend user our [TypeScript receiver scripts](https://github.com/lati111/laravel_datatables) for this, but you can also build your own.

- [Laravel dataproviders](#laravel-dataproviders)
    - [Installation](#installation)
    - [Usage](#usage)
        - [Paginatable](#paginatable)
        - [Searchable](#searchable)
        - [Sortable](#sortable)
        - [Filterable](#filterable)
    - [Requirements](#requirements)

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

[](#installation)

```
composer require lati111/laravel_dataproviders

```

Usage
-----

[](#usage)

To create a basic dataprovider with no additional functions:

```
class Datatable extends Controller
{
    // Use the dataprovider trait to indicate that this is a dataprovider
    use Dataprovider;

    // Method to be called from a route
    public function data(Request $request) {
        // Get the data from the dataprovider trait.
        $data = $this->getData($request);

        // Return the data as a JsonResponse
        response()->json($data, Response::HTTP_OK);
    }

    // Implement the getContent method from the dataprovider trait to set the unmodifed data
    protected function getContent(Request $request): Builder
    {
        // Create a query for orders
        return Order::select();
    }
}
```

### Paginatable

[](#paginatable)

A dataprovider can be made paginatable, meaning the content in seperated into different pages which can be navigated through. To create a paginatable dataprovider, do as follows:

```
class Datatable extends Controller
{
    // Use the dataprovider trait to indicate that this is a dataprovider
    use Dataprovider;
    // Use the paginatable trait to indicate that this dataprovider should be paginatable
    use Paginatable;

    // Method to be called from a route
    public function data(Request $request) {
        // Set the default amount of items per page (normally 10)
        $this->setDefaultPerPage(20);

        // Get the data from the dataprovider trait.
        $data = $this->getData($request);

        // Return the data as a JsonResponse
        response()->json($data, Response::HTTP_OK);
    }

    ...
}
```

You can pass the `page` and `perpage` variables along the request. Page indicates which page should be loaded, while perpage sets the amount of entries that should be loaded.

```
{
  "page": 4,
  "perpage": 10
}
```

Alternatively, you may use `offset` instead of `page` if you want to handle pagination manually, such as in the case of a scroll to load item.

```
{
  "offset": 12,
  "perpage": 8
}
```

### Searchable

[](#searchable)

A dataprovider can be made to be searchable, allowing the user to search the dataprovider for certain values. To make a dataprovider paginatable, you can do the following:

```
class Datatable extends Controller
{
    // Use the dataprovider trait to indicate that this is a dataprovider
    use Dataprovider;
    // Use the paginatable trait to indicate that this dataprovider should be paginatable
    use Searchable;

    // Method to be called from a route
    public function data(Request $request) {
        // Slows down searches but allows the dataprovider to search on aliased column defined in search fields.
        $this->setAliasSearch(true);

        // Get the data from the dataprovider trait.
        $data = $this->getData($request);

        // Return the data as a JsonResponse
        response()->json($data, Response::HTTP_OK);
    }

    // Implement the getSearchFields method from the Searchable trait to set what columns can be searched on
    function getSearchFields(): array
    {
        // Return an array of column names belonging to the model this dataprovider is searching on
        return ['id', 'product_name'];
    }

    ...
}
```

You can pass the `search` variable along the request, indicating which term to search for in the selected columns.

```
{
  "search": "USB"
}
```

### Sortable

[](#sortable)

A dataprovider can be made to be searchable, allowing the user to indicate which columns should be sorted on. To make a dataprovider sortable, you can do the following:

```
class Datatable extends Controller
{
    // Use the dataprovider trait to indicate that this is a dataprovider
    use Dataprovider;
    // Use the paginatable trait to indicate that this dataprovider should be paginatable
    use Sortable;

    function __construct() {
        //when using an aliased column, you can set it in the column aliases array to replace any sorting of `time_since_order` with `created_at`
        $this->columnAliases = ['time_since_order' => 'created_at']
    }

    // Method to be called from a route
    public function data(Request $request) {
        // Get the data from the dataprovider trait.
        $data = $this->getData($request);

        // Return the data as a JsonResponse
        response()->json($data, Response::HTTP_OK);
    }

    // Implement the getAllowedSortColumns method from the Sortable trait to set what columns can be sorted on
    function getAllowedSortColumns(): array
    {
        // Return an array of column names belonging to the model this dataprovider is are allowed to be sorted on
        return ['total_price', 'price', 'amount', 'created_at'];
    }

    ...

}
```

You can pass the a json array of sortables along through the request variables under the key 'sort'. The array should be as follows

```
{
  "sort": {
    "price": "desc",
    "created_at": "desc"
  }
}
```

### Filterable

[](#filterable)

A dataprovider can be made to be filterable, allowing the user to filter on certain values. To make a dataprovider sortable, you can do the following:

```
class Datatable extends Controller
{
    // Use the dataprovider trait to indicate that this is a dataprovider
    use Dataprovider;
    // Use the paginatable trait to indicate that this dataprovider should be paginatable
    use Filterable;

    // Method to be called from a route to get the data
    public function data(Request $request) {
        // Get the data from the dataprovider trait.
        $data = $this->getData($request);

        // Return the data as a JsonResponse
        response()->json($data, Response::HTTP_OK);
    }

    // Method to be called from a route to get filter options
    public function getFilters(Request $request) {
        // Gets either a list of available filters, or a list of available options for a filter if one is specified
        $data = $this->getFilterData($request);

        // Return the data as a JsonResponse
        response()->json($data, Response::HTTP_OK);
    }

    // Implement the getFilterList method from the Filterable trait to set what filters exist
    function getFilterList(): array
    {
        return [
            'customer' => new CustomerFilter(),
            'product' => new ProductFilter(),
        ];
    }

    ...
}
```

Filters must implement the `DataproviderFilterInterface` interface to work, and be constructed as follows:

```
class CustomerFilter implements DataproviderFilterInterface
{
    // Apply the filter to a query
    public function handle(Builder $builder, string $operator, string $value): Builder
    {
        // Perform query actions necessary to enforce the filter
        $builder->where('customer_id', $operator, $value);

        return $builder;
    }

    // Get the details about this filter matching the right format
    public function getInfo(): array
    {
        return [
            'option' => 'customer',
            'operators' => [
                ['operator' => '=', 'text' => 'is'],
                ['operator' => '!=', 'text' => 'is not'],
            ],
            'options' => Product::distinct()->pluck('customer_id'),
        ];
    }
}
```

You can pass the a json array of filters along through the request variables under the key 'sort'. The array should be as follows

```
{
  "filters": [
    {
      "filter": "customer",
      "operator": "!=",
      "value": "34"
    }
  ]
}
```

Requirements
------------

[](#requirements)

- PHP ^8.1
- Laravel ^10.0

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance62

Regular maintenance activity

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~20 days

Recently: every ~70 days

Total

25

Last Release

229d ago

Major Versions

v1.3 → 2.02024-05-17

2.1.7 → 3.0.02024-09-02

PHP version history (2 changes)v1.3PHP ^8.1

2.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/550d377f68c20f21a2424b038f6368c8fb4f84eba7b01e59d8a6d22585fc8ec6?d=identicon)[lati111](/maintainers/lati111)

---

Top Contributors

[![lati111](https://avatars.githubusercontent.com/u/75079614?v=4)](https://github.com/lati111 "lati111 (42 commits)")

### Embed Badge

![Health badge](/badges/lati111-laravel-dataproviders/health.svg)

```
[![Health](https://phpackages.com/badges/lati111-laravel-dataproviders/health.svg)](https://phpackages.com/packages/lati111-laravel-dataproviders)
```

###  Alternatives

[spatie/laravel-query-builder

Easily build Eloquent queries from API requests

4.4k26.9M220](/packages/spatie-laravel-query-builder)[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[flat3/lodata

OData v4.01 Producer for Laravel

96320.9k](/packages/flat3-lodata)[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)[dymantic/laravel-instagram-feed

Fetches the instagram feed for given authenticated profiles

151157.7k](/packages/dymantic-laravel-instagram-feed)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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