PHPackages                             laralabs/datatablejson - 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. [Templating &amp; Views](/categories/templating)
4. /
5. laralabs/datatablejson

AbandonedArchivedLibrary[Templating &amp; Views](/categories/templating)

laralabs/datatablejson
======================

Easily generate DataTable JSON from an eloquent collection and bind it to the view

1.0.2(8y ago)321[1 issues](https://github.com/Laralabs/datatablejson/issues)MIT LicensePHPPHP &gt;=7.0

Since Aug 2Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Laralabs/datatablejson)[ Packagist](https://packagist.org/packages/laralabs/datatablejson)[ RSS](/packages/laralabs-datatablejson/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

DataTableJson for Laravel
=========================

[](#datatablejson-for-laravel)

This package aims to simplify the process of creating JSON data for DataTable components.

Recently I started using a Vue DataTable component and found that I needed a simple way of formatting and passing the data into the view to keep everything tidy.

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

[](#installation)

Install the package via composer

```
{
    "require": {
      "laralabs/datatablejson": "~1.0.1"
    }
}
```

Once you have updated composer, add the Service Provider to your `providers` array within `config/app.php`

```
'providers' => [
    Laralabs\DataTableJson\DataTableJsonServiceProvider::class
];
```

Now you can publish the config file to `config/datatablejson.php`

```
php artisan vendor:publish --tag=config

```

Edit the published configuration file to suit your application.

> **It is recommended that you change the namespace from the default 'window'**

Usage
-----

[](#usage)

Add the trait to the top of your Eloquent Model

```
use DataTableJsonTrait;
```

Add `public $columns = []` to your model, this defines the columns that will be used in the table.

Here is an example of a populated `$columns` array:

```
    public $columns = [
        [
            "label" => "ID",
            "field" => "id",
            "searchable" => true,
            "orderable" => true
        ],
        [
            "label" => "First Name",
            "field" => "first_name",
            "searchable" => true,
            "orderable" => true
        ],
        [
            "label" => "Actions",
            "field" => "actions",
            "searchable" => false,
            "orderable" => false,
            "html" => true,
            "content" => '

                        '
        ]
    ];
```

The `Actions` column in the example shows how you create columns that can include HTML snippets, pull in data from other fields by using `{field_name}`

Once the columns have been defined you can then create a collection and apply the conversion function.

```
$users = Users::all();
$users->toDataTableJson();
```

This will build up the data and prepend it to the view that you specified in the configuration file.

Got a special case and need a different set of fields? You can pass a `$columns` array to this function which will override the columns specified in the model.

```
$columns = [
    [
      "....." => "...."
    ]
]
$users = Users::all();
$users->toDataTableJson($columns);
```

> This package is designed to work well with [MicroDroid/vue-materialize-datatable](https://github.com/MicroDroid/vue-materialize-datatable)

Credits
-------

[](#credits)

Thanks to Jeffrey Way over at Laracasts for his awesome [Laracasts/PHP-Vars-To-Js-Transformer](https://github.com/laracasts/PHP-Vars-To-Js-Transformer) package which allowed me to include the view binding functionality.

Support
-------

[](#support)

Please raise an issue on Github if there is a problem.

License
-------

[](#license)

This is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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 ~9 days

Total

3

Last Release

3236d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e435b69bacc2a02dba78ac929b92950a7b29d496c4164c84cb4b3cdac7d39c82?d=identicon)[Laralabs](/maintainers/Laralabs)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/laralabs-datatablejson/health.svg)

```
[![Health](https://phpackages.com/badges/laralabs-datatablejson/health.svg)](https://phpackages.com/packages/laralabs-datatablejson)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M337](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M169](/packages/laravel-ai)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M123](/packages/roots-acorn)[illuminate/queue

The Illuminate Queue package.

21332.6M1.5k](/packages/illuminate-queue)[spatie/laravel-health

Monitor the health of a Laravel application

87511.3M155](/packages/spatie-laravel-health)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)

PHPackages © 2026

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