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. laralabs/datatablejson

AbandonedArchivedLibrary

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 3d 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 37% 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

3189d 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

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[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.

44643.1k1](/packages/pressbooks-pressbooks)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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