PHPackages                             stevebauman/eloquenttable - 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. [Database &amp; ORM](/categories/database)
4. /
5. stevebauman/eloquenttable

ActiveLibrary[Database &amp; ORM](/categories/database)

stevebauman/eloquenttable
=========================

An HTML table generator for laravel collections

v1.1.7(9y ago)4650.6k[4 issues](https://github.com/stevebauman/eloquent-table/issues)[1 PRs](https://github.com/stevebauman/eloquent-table/pulls)2MITPHPPHP &gt;=5.4.0

Since Nov 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/stevebauman/eloquent-table)[ Packagist](https://packagist.org/packages/stevebauman/eloquenttable)[ RSS](/packages/stevebauman-eloquenttable/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (1)Versions (13)Used By (2)

Eloquent Table
==============

[](#eloquent-table)

[![Travis CI](https://camo.githubusercontent.com/fe6084bcdd4b883965330641c3a0cea349965c5485abe14d1466517952284b41/68747470733a2f2f7472617669732d63692e6f72672f73746576656261756d616e2f656c6f7175656e742d7461626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/stevebauman/eloquent-table)[![Code Climate](https://camo.githubusercontent.com/803052e3786af442aabb0d916e724f2c47c13ee5b85f788ae949b142bc37bb5f/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73746576656261756d616e2f656c6f7175656e742d7461626c652f6261646765732f6770612e737667)](https://codeclimate.com/github/stevebauman/eloquent-table)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/455ec473c6c2891382f0116f64227297ba9a9ba6466b53e9dc7d6ba77300ac63/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73746576656261756d616e2f656c6f7175656e742d7461626c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/stevebauman/eloquent-table/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/b1ced5431ea0007657931daf8da557c253700bd6b67c4b024907a582032d3854/68747470733a2f2f706f7365722e707567782e6f72672f73746576656261756d616e2f656c6f7175656e747461626c652f762f737461626c652e737667)](https://packagist.org/packages/stevebauman/eloquenttable)[![Total Downloads](https://camo.githubusercontent.com/83371f4d032c4f416fdcf4b8b96d82f9415d4136cd89fb2626926e0c0d926a28/68747470733a2f2f706f7365722e707567782e6f72672f73746576656261756d616e2f656c6f7175656e747461626c652f646f776e6c6f6164732e737667)](https://packagist.org/packages/stevebauman/eloquenttable)[![License](https://camo.githubusercontent.com/be77aa7d95a4126f40722108692c7a7a72fe361b7b4abe3a84de97c44503b493/68747470733a2f2f706f7365722e707567782e6f72672f73746576656261756d616e2f656c6f7175656e747461626c652f6c6963656e73652e737667)](https://packagist.org/packages/stevebauman/eloquenttable)

🚨 Abandoned 🚨
-------------

[](#-abandoned-)

I'd heavily recommend the use of [Orchestra/HTML](https://github.com/orchestral/html) over this package, as their solution is further tested, complete, and much more robust. This package will receive **no further updates**.

If you would like to be a maintainer of this package, please contact me at [steven\_bauman@outlook.com](mailto:steven_bauman@outlook.com), or create an issue.

Thank you!

### Description

[](#description)

Eloquent table is an HTML table generator for laravel collections.

### Installation

[](#installation)

Include the package in `composer.json`:

```
"stevebauman/eloquenttable": "1.1.*"

```

Now perform a `composer update`.

#### Laravel 4

[](#laravel-4)

Include the service providers in the *bottom* `app/config/app.php` config file:

```
'Stevebauman\EloquentTable\PaginationServiceProvider',
'Stevebauman\EloquentTable\EloquentTableServiceProvider',

```

Publish the config file (optional)

```
php artisan config:publish stevebauman/eloquenttable

```

#### Laravel 5

[](#laravel-5)

Include the service providers in the *bottom* `config/app.php` config file:

```
'Stevebauman\EloquentTable\EloquentTableServiceProvider',

```

Publish the config file (mandatory in Laravel 5)

```
php artisan vendor:publish

```

You're good to go!

> **Note**: The `showPages()` method below in unavailable in Laravel 5 due to the pagination changes. You'll need to display your pages manually using the `render()` method shown here:

### Usage

[](#usage)

Insert the trait on your model:

```
class Book extends Eloquent {

    use \Stevebauman\EloquentTable\TableTrait;

    protected $table = 'books';

}

```

Grab records from your model like usual:

```
$books = Books::get();

return view('books.index', compact('books'));

```

Inside your blade view, we just specify the columns we want to show, and then call the render method:

```
{!!
    $books->columns(array(
        'id' => 'ID',
        'title' => 'Title',
        'author' => 'Authored By'
    ))
    ->render()
!!}

```

##### Handling relationship values using `means($column, $relationship)`:

[](#handling-relationship-values-using-meanscolumn-relationship)

```
{!!
    $books->columns(array(
        'id' => 'ID',
        'title' => 'Title',
        'author' => 'Authored By',
        'owned_by' => 'Owned By',
    ))
    ->means('owned_by', 'user.first_name')
    ->render()
!!}

```

The model books, needs to have a user method defining it's relation for this to work.

You must also use 'dot' notation to indicate the relationship.

##### Customizing the display of the column value using `modify($column, $closure)`:

[](#customizing-the-display-of-the-column-value-using-modifycolumn-closure)

```
{!!
    $books->columns(array(
        'id' => 'ID',
        'title' => 'Title',
        'author' => 'Authored By',
        'owned_by' => 'Owned By',
    ))
    ->means('owned_by', 'user')
    ->modify('owned_by', function($user, $book) {
        return $user->first_name . ' ' . $user->last_name;
    })
    ->render()
!!}

```

Using modify, we can specify the column we want to modify, and the function will return the current relationship record (if the column is a relationship), as well as the current base record, in this case the book.

##### Customizing the attributes of each cell of a column using `modifyCell($column, $closure)`:

[](#customizing-the-attributes-of-each-cell-of-a-column-using-modifycellcolumn-closure)

```
{!!
    $books->columns(array(
        'id' => 'ID',
        'title' => 'Title',
        'author' => 'Authored By',
        'owned_by' => 'Owned By',
    ))
    ->means('owned_by', 'user')
    ->modifyCell('owned_by', function($user) {
        return array('class' => $user->role);
    })
    ->render()
!!}

```

Using modifyCell, we can specify the column of the cell we want to modify, and the function should return an array of attributes to be added to the cell.

##### Customizing the attributes of each row in the table using `modifyRow($name, $closure)`:

[](#customizing-the-attributes-of-each-row-in-the-table-using-modifyrowname-closure)

```
{!!
    $books->columns(array(
        'id' => 'ID',
        'title' => 'Title',
        'author' => 'Authored By',
        'owned_by' => 'Owned By',
    ))
    ->means('owned_by', 'user')
    ->modifyRow('mod1', function($user) {
        return array('id' => 'user-'.$user->id);
    })
    ->render()
!!}

```

Using modifyRow, we can add named modifications ('mod1' in our previous example), and the function should return an array of attributes to be added to each row.

##### With eloquent-table, we can also generate sortable links for columns easily:

[](#with-eloquent-table-we-can-also-generate-sortable-links-for-columns-easily)

In your controller:

```
$books = Book::sort(Input::get('field'), Input::get('sort'))->get();

```

In your view:

```
{!!
    $books->columns(array(
        'id' => 'ID',
        'title' => 'Title',
        'author' => 'Authored By',
        'owned_by' => 'Owned By',
    ))
    ->sortable(array('id', 'title'))
    ->render()
!!}

```

A link will be generated inside the column header that will be clickable. The HTML generated will look like:

```

    ID

```

##### What about if we want to combine this all together, with pagination and sorting? Easy:

[](#what-about-if-we-want-to-combine-this-all-together-with-pagination-and-sorting-easy)

In your controller:

```
$books = Book::sort(Input::get('field'), Input::get('sort'))->paginate(25);

return view('books.index', compact('books'));

```

In your view:

```
{!!
    $books->columns(array(
        'id' => 'ID',
        'title' => 'Title',
        'author' => 'Authored By',
        'owned_by' => 'Owned By',
        'publisher' => 'Publisher',
    ))
    ->means('owned_by', 'user')
    ->modify('owned_by', function($user, $book) {
        return $user->first_name . ' ' . $user->last_name;
    })
    ->means('publisher', 'publisher')
    ->modify('publisher', function($publisher, $book) {
        return 'The publisher of this book: '. $publisher->name;
    })
    ->sortable(array('id', 'title'))
    ->showPages()
    ->render()
!!}

```

##### What if I want to generate a table for a relationship?:

[](#what-if-i-want-to-generate-a-table-for-a-relationship)

In your controller:

```
$book = Book::with('authors')->find(1);

return view('book.show', compact('book'));

```

In this case, the book is going to have many authors (`hasMany` relationship)

In your view:

```
{!!
    $book->authors->columns(
        'id' => 'ID',
        'name' => 'Name',
        'books' => 'Total # of Books'
    )
    ->means('books', 'num_of_books')
    ->render()
!!}

```

Keep in mind, we cannot paginate the table, or provide sortable columns on relationships. If you need this, grab it separately:

In your controller:

```
$book = Book::find(1);

$authors = Authors::where('book_id', $book->id)->paginate(25);

return view('books.show', array(
    'book' => $book,
    'authors' => $authors,
));

```

In your view:

```
{!!
    $authors->columns(array(
        'name' => 'Name',
    ))->render()
!!}

```

##### Customizing table attributes using `attributes($attributes = array())`

[](#customizing-table-attributes-using-attributesattributes--array)

```
{!!
    $authors->columns(array(
        'name' => 'Name',
    ))
    ->attributes(array(
        'id' => 'table-1',
        'class' => 'table table-striped table-bordered',
    ))
    ->render()
!!}

```

##### Showing your pages somewhere else:

[](#showing-your-pages-somewhere-else)

Just don't call the `showPages()` method on the collection and put your pages somewhere on your page like you would regularly do.

```
{!!
    $authors->columns(array(
        'name' => 'Name',
    ))
    ->attributes(array(
        'id' => 'table-1',
        'class' => 'table table-striped table-bordered',
    ))
    ->render()
!!}

{!! $authors->appends(Input::except('page'))->links() !!}

```

##### Why is a pagination service provider required?

[](#why-is-a-pagination-service-provider-required)

When calling `paginate()` on your models and/or collections, a different collection instance is returned. Unfortunately the only solution is to override the default paginator instance. However, this paginator extends laravel's built in paginator, so absolutely no functionality is removed or lost.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 91.8% 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 ~84 days

Recently: every ~172 days

Total

11

Last Release

3374d ago

### Community

Maintainers

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

---

Top Contributors

[![stevebauman](https://avatars.githubusercontent.com/u/6421846?v=4)](https://github.com/stevebauman "stevebauman (90 commits)")[![photonite](https://avatars.githubusercontent.com/u/7004014?v=4)](https://github.com/photonite "photonite (4 commits)")[![ValavBatka](https://avatars.githubusercontent.com/u/6774300?v=4)](https://github.com/ValavBatka "ValavBatka (2 commits)")[![jonasof](https://avatars.githubusercontent.com/u/5995209?v=4)](https://github.com/jonasof "jonasof (1 commits)")[![marknl](https://avatars.githubusercontent.com/u/4932990?v=4)](https://github.com/marknl "marknl (1 commits)")

---

Tags

phplaravelhtmleloquenttable

### Embed Badge

![Health badge](/badges/stevebauman-eloquenttable/health.svg)

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

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591452.8k2](/packages/spiritix-lada-cache)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5768.3k](/packages/io238-laravel-iso-countries)[sebastiaanluca/laravel-boolean-dates

Automatically convert Eloquent model boolean attributes to dates (and back).

40115.4k1](/packages/sebastiaanluca-laravel-boolean-dates)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

276.8k](/packages/ntanduy-cloudflare-d1-database)

PHPackages © 2026

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