PHPackages                             reckless/laravel-table - 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. reckless/laravel-table

ActiveLibrary

reckless/laravel-table
======================

Table functionality for Laravel models

0.3.4(10y ago)0677↓100%MITPHPPHP &gt;=5.3.0

Since Mar 23Pushed 1y agoCompare

[ Source](https://github.com/RecklessAgency/laravel-table)[ Packagist](https://packagist.org/packages/reckless/laravel-table)[ RSS](/packages/reckless-laravel-table/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (20)Used By (0)

Laravel Tables
==============

[](#laravel-tables)

[![Made for Laravel 5](https://camo.githubusercontent.com/ba235a532dde071f0fc1985567dc41cace47c7ea8d65489ac46bdb05e75f46cc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d352e302d7265642e737667)](http://laravel.com/)[![Latest Tag](https://camo.githubusercontent.com/15b9629a22a9707147911a1929aa1ec690283585995da8d05752fb3b144c8639/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f6762726f636b2f6c61726176656c2d7461626c652e737667)](https://github.com/gbrock/laravel-table/releases)

This package contains flexible ways of rendering Eloquent collections as dynamic HTML tables. This includes techniques for sortable columns, customizable cell data, automatic pagination, user-definable rows-per-page, batch action handling, and extensible filtering (coming soon).

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

[](#installation)

Require the package in your `composer.json`:

```
"gbrock/laravel-table": "dev-master"
```

Add the service provider to `config/app.php` and, optionally, the Facade:

```
'Gbrock\Table\Providers\TableServiceProvider',
...
'Table'      => 'Gbrock\Table\Facades\Table',
```

Publish the views and config:

```
php artisan vendor:publish

```

Usage
-----

[](#usage)

**In order to render an HTML table of Eloquent models into a view**, first create a Table object, passing in your model collection (this could be done in your controller, repository, or any service class):

```
$rows = User::get(); // Get all users from the database
$table = Table::create($rows); // Generate a Table based on these "rows"
```

Then pass that object to your view:

```
return view('users.index', ['table' => $table]);
```

In your view, the table object can be rendered using its `render` function:

```
{!! $table->render() !!}
```

Which would render something like this:

[![Basic example](https://raw.githubusercontent.com/gbrock/laravel-table/master/examples/images/basic_initialization.png)](https://raw.githubusercontent.com/gbrock/laravel-table/master/examples/images/basic_initialization.png)

### Sorting

[](#sorting)

To add links in your headers which sort the indicated column, add the `Sortable` trait to your model. Since no fields are allowed to be sorted by default (for security reasons), also add a `sortable` array containing allowed fields.

```
use Gbrock\Table\Traits\Sortable;

class User extends Model {

	use Sortable;

    /**
     * The attributes which may be used for sorting dynamically.
     *
     * @var array
     */
    protected $sortable = ['username', 'email', 'created_at'];
```

This adds the `sortable` scope to your model, which you should use when retrieving rows. Altering our example, `$rows = User::get()` becomes:

```
$rows = User::sorted()->get(); // Get all users from the database, but listen to the user Request and sort accordingly
```

Now, our table will be rendered with links in the header:

[![Sortable example](https://raw.githubusercontent.com/gbrock/laravel-table/master/examples/images/sortable_initialization.png)](https://raw.githubusercontent.com/gbrock/laravel-table/master/examples/images/sortable_initialization.png)

The links will contain query strings like `?sort=username&direction=asc`.

### Pagination

[](#pagination)

If you paginate your Eloquent collection, it will automatically be rendered below the table:

```
$rows = User::sorted()->paginate(); // Get all users from the database, sort, and paginate
```

Customization
-------------

[](#customization)

### Columns

[](#columns)

Pass in a second argument to your database call / Table creation, **columns**:

```
 $table = Table::create($rows, ['username', 'created_at']); // Generate a Table based on these "rows"
```

### Cells

[](#cells)

You can specify a closure to use when rendering cell data when adding the column:

```
// We pass in the field, label, and a callback accepting the model data of the row it's currently rendering
$table->addColumn('created_at', 'Added', function($model) {
    return $model->created_at->diffForHumans();
});
```

Also, since the table is accessing our model's attributes, we can add or modify any column key we'd like by using [accessors](http://laravel.com/docs/5.0/eloquent#accessors-and-mutators):

```
    protected function getRenderedCreatedAtAttribute()
    {
        // We access the following diff string with "$model->rendered_created_at"
        return $this->created_at->diffForHumans();
    }
```

The default view favors the `rendered_foobar` attribute, if present, otherwise it uses the `foobar` attribute.

### View

[](#view)

A copy of the view file is located in `/resources/vendor/gbrock/tables/` after you've run `php artisan vendor:publish`. You can copy this file wherever you'd like and alter it, then tell your table to use the new view:

```
$table->setView('users.table');
```

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75.4% 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 ~21 days

Recently: every ~1 days

Total

11

Last Release

3857d ago

### Community

Maintainers

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

---

Top Contributors

[![gbrock](https://avatars.githubusercontent.com/u/4151394?v=4)](https://github.com/gbrock "gbrock (46 commits)")[![brynj-digital](https://avatars.githubusercontent.com/u/13166627?v=4)](https://github.com/brynj-digital "brynj-digital (13 commits)")[![ddxor](https://avatars.githubusercontent.com/u/7305588?v=4)](https://github.com/ddxor "ddxor (1 commits)")[![grinry](https://avatars.githubusercontent.com/u/5575688?v=4)](https://github.com/grinry "grinry (1 commits)")

---

Tags

laravelhtmlmodelfilteringtablesorting

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[gbrock/laravel-table

Table functionality for Laravel models

7644.3k](/packages/gbrock-laravel-table)[indexzer0/eloquent-filtering

Powerful eloquent filtering

22425.9k3](/packages/indexzer0-eloquent-filtering)[akaunting/laravel-sortable

Sortable behavior package for Laravel

27175.6k](/packages/akaunting-laravel-sortable)[phaza/single-table-inheritance

Single Table Inheritance Trait

1515.8k](/packages/phaza-single-table-inheritance)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

116.6k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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