PHPackages                             evgeniy-silantev/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. evgeniy-silantev/laravel-table

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

evgeniy-silantev/laravel-table
==============================

Generate tables with Laravel.

1.2.9(6y ago)012MITPHPPHP ^7.1

Since Feb 12Pushed 6y agoCompare

[ Source](https://github.com/EvgeniySilantev/laravel-table)[ Packagist](https://packagist.org/packages/evgeniy-silantev/laravel-table)[ Docs](https://github.com/EvgeniySilantev/laravel-table)[ RSS](/packages/evgeniy-silantev-laravel-table/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (8)Versions (30)Used By (0)

Generate tables with Laravel
============================

[](#generate-tables-with-laravel)

[![Source Code](https://camo.githubusercontent.com/233c90c36da00abf5a8c5584bf1fc003231812a36997d29bea0f5afabbbb8daa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6f6b6970612f6c61726176656c2d2d7461626c652d626c75652e737667)](https://github.com/Okipa/laravel-table)[![Latest Version](https://camo.githubusercontent.com/d5fd1cdfc4263f9944782a96e00523c9a4ad3b82248fe26697459a62f4516a69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6f6b6970612f6c61726176656c2d7461626c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Okipa/laravel-table/releases)[![Total Downloads](https://camo.githubusercontent.com/555a2a6e5dda98d3ed68ce3a4a85f3981a10432bc0da0bb9fc87deef8af16495/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6b6970612f6c61726176656c2d7461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/okipa/laravel-table)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)[![Build Status](https://camo.githubusercontent.com/d81b3a7ba26418396f2a1bcd0e8028a42463bce447ecb637d9fdcb5b9d6d6162/68747470733a2f2f7472617669732d63692e6f72672f4f6b6970612f6c61726176656c2d7461626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Okipa/laravel-table)[![Coverage Status](https://camo.githubusercontent.com/8b7275530245cfc5aee09855bcb8e02ddb16b1b9c1b6ef01b67051f5f7ae53e2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4f6b6970612f6c61726176656c2d7461626c652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Okipa/laravel-table?branch=master)[![Quality Score](https://camo.githubusercontent.com/da8ee46d9766bfaca4859a9e3a8a95b3539bae503107eaeb8c291a7fba226ae7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4f6b6970612f6c61726176656c2d7461626c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Okipa/laravel-table/?branch=master)

Laravel Table allows you to easily render tables in your views, directly built from PHP code.
This package is shipped with a pre-configuration for `Bootstrap 4.*` and `FontAwesome 5`.
**However**, the templates customization makes it very simple to use with another UI framework.

Compatibility
-------------

[](#compatibility)

Laravel versionPHP versionPackage version^5.5^7.1^1.0Usage
-----

[](#usage)

Prepare the table configuration somewhere in your code and pass it to the view :

```
$table = (new \Okipa\LaravelTable\Table)->model(\App\News::class)->routes([
    'index'   => ['name' => 'users.index'],
    'create'  => ['name' => 'user.create'],
    'edit'    => ['name' => 'user.edit'],
    'destroy' => ['name' => 'user.destroy'],
])->destroyConfirmationHtmlAttributes(function (User $user) {
    return [
        'data-confirm' => 'Are you sure you want to delete the user ' . $user->name . ' ?',
    ];
});
$table->column('first_name')->sortable(true)->searchable();
$table->column('last_name')->sortable()->searchable();
$table->column('email')->sortable()->searchable();
```

In your view, simply render your table like this :

```
{{ $table }}
```

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Customize translations](#customize-translations)
- [Customize templates](#customize-templates)
- [Table API](#table-api)
    - [-&gt;model()](#table-model)
    - [-&gt;identifier()](#table-identifier)
    - [-&gt;request()](#table-request)
    - [-&gt;routes()](#table-routes)
    - [-&gt;destroyConfirmationHtmlAttributes()](#table-destroyConfirmationHtmlAttributes)
    - [-&gt;rowsNumber()](#table-rowsNumber)
    - [-&gt;rowsNumberSelectionActivation()](#table-rowsNumberSelectionActivation)
    - [-&gt;query()](#table-query)
    - [-&gt;appends()](#table-appends)
    - [-&gt;containerClasses()](#table-containerClasses)
    - [-&gt;tableClasses()](#table-tableClasses)
    - [-&gt;trClasses()](#table-trClasses)
    - [-&gt;thClasses()](#table-thClasses)
    - [-&gt;tdClasses()](#table-tdClasses)
    - [-&gt;rowsConditionalClasses()](#table-rowsConditionalClasses)
    - [-&gt;disableRows()](#table-disableRows)
    - [-&gt;tableTemplate()](#table-tableTemplate)
    - [-&gt;theadTemplate()](#table-theadTemplate)
    - [-&gt;tbodyTemplate()](#table-tbodyTemplate)
    - [-&gt;resultsTemplate()](#table-resultsTemplate)
    - [-&gt;tfootTemplate()](#table-tfootTemplate)
    - [-&gt;column()](#table-column)
    - [-&gt;result()](#table-result)
- [Column API](#column-api)
    - [-&gt;classes()](#column-classes)
    - [-&gt;title()](#column-title)
    - [-&gt;sortable()](#column-sortable)
    - [-&gt;searchable()](#column-searchable)
    - [-&gt;dateTimeFormat()](#column-dateTimeFormat)
    - [-&gt;button()](#column-button)
    - [-&gt;link()](#column-link)
    - [-&gt;icon()](#column-icon)
    - [-&gt;stringLimit()](#column-stringLimit)
    - [-&gt;value()](#-value)
    - [-&gt;html()](#-html)
- [Result API](#result-api)
    - [-&gt;title()](#result-title)
    - [-&gt;html()](#result-html)
    - [-&gt;classes()](#result-classes)
- [Tips](#tips)
- [Usage examples](#usage-examples)
    - [Basic](#basic)
    - [Advanced](#advances)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [Licence](#license)

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

[](#installation)

- Install the package with composer :

```
composer require "evgeniy-silantev/laravel-table:^1.0"
```

Configuration
-------------

[](#configuration)

Publish the package configuration and override the available config values :

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

Customize translations
----------------------

[](#customize-translations)

To customize the existing translations, publish the packages translations files to make the wanted changes :

```
php artisan vendor:publish --tag=laravel-table:translations
```

Customize templates
-------------------

[](#customize-templates)

Customize the used templates to make this package fit to your needs.
Publish the views with the command :

```
php artisan vendor:publish --tag=laravel-table:views
```

Table API
---------

[](#table-api)

⚠️ All the following methods are chainable with `\Okipa\LaravelTable\Table` object **except the [-&gt;column()](#table-column) and the [-&gt;result()](#table-result) methods** (returning respectively `\Okipa\LaravelTable\Column` and `\Okipa\LaravelTable\Result` objects).

### -&gt;model()

[](#-model)

> Set the model used during the table generation.

**Notes:**

- Signature : `model(string $tableModel): \Okipa\LaravelTable\Table`
- Required

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->model(\App\News::class);
```

### -&gt;identifier()

[](#-identifier)

> Set the table identifier, in order to automatically generate its id and to customize all the interaction fields in case of multiple tables used on a single view : the interactions with the table like sorting, searching an more will only have an impact on the identified table.

**Notes:**

- Signature : `identifier(string $identifier): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->identifier('Your identifier');
```

### -&gt;request()

[](#-request)

> Set the request used for the table generation.

**Notes:**

- Signature : `request(Request $request): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
// example in a controller
public function index(Request $request) {
    app(\Okipa\LaravelTable\\Okipa\LaravelTable\Table::class)->request($request);
    // ...
}
```

### -&gt;routes()

[](#-routes)

> Set the routes used during the table generation.
> The routes declarations will be used for the following features :
>
> - `index` (required) : used for the rows number definition, sort and search features.
> - `create` (optional) : the **create** button is displayed if this route is declared. The button used this route to redirect to the model creation page.
> - `edit` (optional) : the **edit** button is displayed on each row if this route is declared. The route is used to redirect to the model edition page.
> - `destroy` (optional) : the **destroy** button is displayed on each row if this route is declared. The route is used to trigger the model destroy action.
> - `show` (optional) : the **show** button is displayed on each row if this route is declared. The route is used to redirect to the model show page.

**Note :**

- Signature : `routes(array $routes): \Okipa\LaravelTable\Table`
- Required
- Each route have to be defined with the following structure :

```
// example
[
    'index' => [
        // required
        'name' => 'news.index',
        // optional
        'params' => [
            // set route params
            // or do not declare it
        ]
    ]
];
```

- ⚠️ As the current model is always provided as a param to the `edit`, `destroy` and `show` routes, you do not have to define it in the `->routes()` call. You also should declare your routes carefully to avoid errors. See the examples bellow :

```
    // assuming your declared your route with implicit binding :
    Route::get('parent/{$parent}/user/edit/{$user}/child/{$child}', 'UsersController@edit')->name('user.edit');
    // you'll have to declare your params with keys as following :
    (new Table)->model(User::class)->routes([
        // ...
        'edit'    => ['name'=> 'user.edit', 'params' => ['parent' => $parent, 'child' => $child]],
        // ...
    ])
    // because the route will be generated with the table related model as first param (the params order differs from the declaration) :
    route('user.edit, [$user, 'parent' => $parent, 'child' => $child]);
```

```
    // now imagine your route is declared with the table related model as first param like this :
    Route::get('/user/edit/{$user}/child/{$child}/{otherParam}', 'UsersController@edit')->name('user.edit');
    // in this case only, you will be able to declare your routes without keys :
    (new Table)->model(User::class)->routes([
        // ...
        'edit'    => ['name'=> 'user.edit', 'params' => [$child, 'otherValue']],
        // ...
    ])
    // because the route params are given in the same order as the route declaration :
    route('user.edit, [$user, $child, 'otherValue']);
```

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->routes([
    'index' => ['name' => 'news.index'],
    'create' => ['name' => 'news.create', 'params' => ['param1' => 'value1']],
    'edit' => ['name' => 'news.edit', 'params' => ['param2' => 'value2']],
    'destroy' => ['name' => 'news.destroy'],
    'show' => ['name' => 'news.show'],
]);
```

### -&gt;rowsNumber

[](#-rowsnumber)

> Override the config default number of rows displayed on the table.
> The default number of displayed rows is defined in the `config('laravel-table.value.rowsNumber')` config value.
> Set `false` to display all the models contained in database.

**Note :**

- Signature : `rowsNumber(?int $rows): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->rowsNumber(50);
// or
(new \Okipa\LaravelTable\Table)->rowsNumber(null);
```

### -&gt;rowsNumberSelectionActivation()

[](#-rowsnumberselectionactivation)

> Override the default rows number selection activation status.
> Calling this method displays a rows number input that enable the user to choose how much rows to show.
> The default rows number selection activation status is managed by the `config('laravel-table.value.rowsNumberSelectionActivation')` value.

**Note :**`

- Signature : `rowsNumberSelectionActivation($activate = true): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->rowsNumberSelectionActivation(false);
```

### -&gt;query()

[](#-query)

> Set the query closure that will be executed during the table generation.
> For example, you can define your joined tables here.
> The closure let you manipulate the following attribute : `$query`.

**Note :**

- Signature : `query(Closure $queryClosure): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->query(function($query){
    $query->select('users.*');
    $query->addSelect('companies.name as company');
    $query->join('users', 'users.id', '=', 'companies.owner_id');
});
```

### -&gt;appends()

[](#-appends)

> Add an array of arguments to append to the paginator and to the following table actions :
>
> - row number selection
> - searching
> - search canceling
> - sorting.

**Note :**

- Signature : `appends(array $appendedValues): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->appends(request()->only('status'));
```

### -&gt;containerClasses()

[](#-containerclasses)

> Override default table container classes.
> The default container classes are defined in the `config('laravel-table.classes.container')` config value.

**Note :**

- Signature : `containerClasses(array $containerClasses): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->containerClasses(['set', 'your', 'classes']);
```

### -&gt;tableClasses()

[](#-tableclasses)

> Override default table classes.
> The default table classes are defined in the `config('laravel-table.classes.table')` config value.

**Note :**

- Signature : `tableClasses(array $tableClasses): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->tableClasses(['set', 'your', 'classes']);
```

### -&gt;trClasses()

[](#-trclasses)

> Override default table tr classes.
> The default tr classes are defined in the `config('laravel-table.classes.tr')` config value.

**Note :**

- Signature : `trClasses(array $trClasses): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->trClasses(['set', 'your', 'classes']);
```

### -&gt;thClasses()

[](#-thclasses)

> Override default table tr classes.
> The default th classes are defined in the `config('laravel-table.classes.th')` config value.

**Note :**

- Signature : `thClasses(array $thClasses): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->thClasses(['set', 'your', 'classes']);
```

### -&gt;tdClasses()

[](#-tdclasses)

> Override default table td classes.
> The default td classes are defined in the `config('laravel-table.classes.td')` config value.

**Note :**

- Signature : `tdClasses(array $tdClasses): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->tdClasses(['set', 'your', 'classes']);
```

### -&gt;rowsConditionalClasses()

[](#-rowsconditionalclasses)

> Set rows classes when the given conditions are respected.
> The closure let you manipulate the following attribute : `$model`. ` **Note :**

- Signature : `rowsConditionalClasses(Closure $rowClassesClosure, array $rowClasses): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->rowsConditionalClasses(function($model){
    return $model->hasParticularAttribute;
}, ['set', 'your', 'classes']);
```

### -&gt;destroyConfirmationHtmlAttributes()

[](#-destroyconfirmationhtmlattributes)

> Define html attributes on the destroy buttons to handle dynamic javascript destroy confirmations.
> The closure let you manipulate the following attribute : `$model`.
> **Beware :** the management of the destroy confirmation is on you, if you do not setup a javascript treatment to ask a confirmation, the destroy action will be directly executed.

**Note :**

- Signature : `destroyConfirmationHtmlAttributes(Closure $destroyConfirmationClosure): \Okipa\LaravelTable\Table`
- Optional (but strongly recommended !)

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->destroyHtmlAttributes(function($model){
    return ['data-confirm' => __('Are you sure you want to delete the user :name ?', [
        'name' => $model->name
    ])];
});
```

**Javascript snippet example :**

```
// example of javascript snippet to ask a confirmation before executing the action
// this example assume that a bootstrap modal component has been included in your view
// https://getbootstrap.com/docs/4.3/components/modal/#modal-components
const destroyButton = $('form.destroy button[type="submit"]');
destroyButton.click((e) => {
  e.preventDefault();
  const $this = $(e.target);
  const message = $this.data("confirm");
  const confirmationModal = $("#confirmationModal");
  confirmationModal.find(".modal-body").text(message);
  confirmationModal.modal("show");
});
```

### -&gt;disableRows()

[](#-disablerows)

> Set the disable lines closure that will be executed during the table generation.
> The optional second param let you override the classes that will be applied for the disabled lines.
> By default, the « config('laravel-table.classes.disabled') » config value is applied.
> For example, you can disable the current logged user to prevent him being edited or deleted from the table.
> The closure let you manipulate the following attribute : `$model`.

**Note :**

- Signature : `disableRows(Closure $rowDisableClosure, array $classes = []): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->disableRows(function($user){
    return $user->id = auth()->id;
}, ['bg-danger', 'text-primary']);
```

### -&gt;tableTemplate()

[](#-tabletemplate)

> Set a custom template path for the table component.
> The default table template path is defined in the `config('laravel-table.template.table')` config value.

**Note :**

- Signature : `tableTemplate(string $tableComponentPath): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->tableTemplate('tailwindCss.table');
```

### -&gt;theadTemplate()

[](#-theadtemplate)

> Set a custom template path for the thead component.
> The default thead template path is defined in the `config('laravel-table.template.thead')` config value.

**Note :**

- Signature : `theadTemplate(string $theadComponentPath): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->theadTemplate('tailwindCss.thead');
```

### -&gt;tbodyTemplate()

[](#-tbodytemplate)

> Set a custom template path for the tbody component.
> The default tbody template path is defined in the `config('laravel-table.template.tbody')` config value.

**Note :**

- Signature : `tbodyTemplate(string $tbodyComponentPath): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->tbodyTemplate('tailwindCss.tbody');
```

### -&gt;resultsTemplate()

[](#-resultstemplate)

> Set a custom template path for the results component.
> The default results template path is defined in the `config('laravel-table.template.results')` config value.

**Note :**

- Signature : `resultsTemplate(string $resultsComponentPath): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->resultsComponentPath('tailwindCss.results');
```

### -&gt;tfootTemplate()

[](#-tfoottemplate)

> Set a custom template path for the tfoot component.
> The default tfoot template path is defined in the `config('laravel-table.template.tfoot')` config value.

**Note :**

- Signature : `tfootTemplate(string $tfootComponentPath): \Okipa\LaravelTable\Table`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->tfootTemplate('tailwindCss.tfoot');
```

### -&gt;column()

[](#-column)

> Add a column that will be displayed in the table.
> The column key is optional if the column is not declared as sortable or searchable.

**Note :**

- Signature : `column(string $databaseColumn = null): \Okipa\LaravelTable\Column`
- Required
- \*\*Warning : \*\* this method should not be chained with the other `\Okipa\LaravelTable\Table` methods because it returns a `\Okipa\LaravelTable\Column` object. See the use case examples to check how to use this method.

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column('email');
```

### -&gt;result()

[](#-result)

> Add a result row that will be displayed at the bottom of the table.

**Note :**

- Signature : `result(): Result`
- Optional
- \*\*Warning : \*\* this method should not be chained with the other `\Okipa\LaravelTable\Table` methods because it returns a `\Okipa\LaravelTable\Result` object. See the use case examples to check how to use this method.

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->result();
```

Column API
----------

[](#column-api)

⚠️ All the column methods are chainable with `\Okipa\LaravelTable\Column` object.

### -&gt;classes()

[](#-classes)

> Set the custom classes that will be applied on this column only.

**Note :**

- Signature : `classes(array $classes): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column()->classes(['font-weight-bold']);
```

### -&gt;title()

[](#-title)

> Set the column title or override the default (`__('validation.attributes.[column key])`) title generated from the column name.

**Note :**

- Signature : `title(string $title = null): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column()->title('E-mail');
```

### -&gt;sortable()

[](#-sortable)

> Make the column sortable.
> You also can choose to set the column sorted by default.
> If no column is sorted by default, the first one will be automatically sorted.

**Note :**

- Signature : `sortable(bool $sortByDefault = false, $sortDirection = 'asc'): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column('email')->sortable();
// alternative
(new \Okipa\LaravelTable\Table)->column('email')->sortable(true, 'desc');
```

### -&gt;searchable()

[](#-searchable)

> Make the column searchable.
> The first param allows you to precise the searched database table (can references a database table alias).
> The second param allows you to precise the searched database attributes (if not precised, the table database column is searched).

**Note :**

- Signature : `public function searchable(string $databaseSearchedTable = null, array $databaseSearchedColumns = []): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
// example 1
(new \Okipa\LaravelTable\Table)->column('email')->searchable();
// example 2
$table = (new \Okipa\LaravelTable\Table)->model(\App\User::class)->query(function($query) {
    $query->select('users.*');
    $query->addSelect('companies.name as company');
    $query->join('companies', 'companies.owner_id', '=', 'users.id');
});
$table->column('company')->searchable('companies', ['name']);
// example 3
$table = (new \Okipa\LaravelTable\Table)->model(\App\User::class)->query(function($query) {
    $query->select('users.*');
    $query->addSelect(\DB::raw('CONCAT(companies.name, " ", companies.activity) as company'));
    $query->join('companies as companiesAliasedTable', 'companies.owner_id', '=', 'users.id');
});
$table->column('company')->searchable('companiesAliasedTable', ['name', 'activity']);
```

### -&gt;dateTimeFormat()

[](#-datetimeformat)

> Set the format for a datetime, date or time database column (optional).
> (Carbon::parse($value)-&gt;format($format) method is used under the hood).

**Note :**

- Signature : `dateTimeFormat(string $dateTimeFormat): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column('created_at')->dateTimeFormat('d/m/Y H:i');
```

### -&gt;button()

[](#-button)

> Display the column as a button with the given classes.

**Note :**

- Signature : `button(array $buttonClasses = []): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column('email')->button(['btn', 'btn-sm', 'btn-primary']);
```

### -&gt;link()

[](#-link)

> Wrap the column value into a `` component.
> You can declare the link as a string or as a closure which will let you manipulate the following attributes : `$model`, `$column`.
> If no url is declared, it will be set with the column value.

**Note :**

- Signature : `link($url = null): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
// example 1
(new \Okipa\LaravelTable\Table)->column('url')->link();
// example 2
(new \Okipa\LaravelTable\Table)->column()->link(route('news.index'));
// example 3
(new \Okipa\LaravelTable\Table)->column()->link(function($news) {
    return route('news.show', $news);
});
```

### -&gt;icon()

[](#-icon)

> Add an icon before the displayed value.
> Set the second param as true if you want the icon to be displayed even if the column has no value.

**Note :**

- Signature : `icon(string $icon, bool $displaydisplayIconWhenNoValue = false): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column('email')->icon('', true);
```

### -&gt;stringLimit()

[](#-stringlimit)

> Set the string value display limitation.
> Shows "..." when the limit is reached.

**Note :**

- Signature : `stringLimit(int $stringLimit): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column('email')->stringLimit(30);
```

### -&gt;value()

[](#-value)

> Display a custom value for the column.
> The closure let you manipulate the following attributes : `$model`, `$column`.

**Note :**

- Signature : `value(Closure $valueClosure): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column()->value(function($user) {
    return config('users.type.' . $user->type_id);
});
```

### -&gt;html()

[](#-html)

> Display a custom HTML for the column.
> The closure let you manipulate the following attributes : `$model`, `$column`.

**Note :**

- Signature : `html(Closure $htmlClosure): \Okipa\LaravelTable\Column`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->column()->html(function($user) {
    return '' . $user->first_name . '';
});
```

Result API
----------

[](#result-api)

⚠️ All the result methods are chainable with `\Okipa\LaravelTable\Result` object.

### -&gt;title()

[](#-title-1)

> Set the result row title.

**Note :**

- Signature : `title(string $title): \Okipa\LaravelTable\Result`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->result()->title('Turnover total');
```

### -&gt;html()

[](#-html-1)

> Display a HTML output for the result row.
> The closure let you manipulate the following attributes : `$displayedList`.

**Note :**

- Signature : `html(Closure $htmlClosure): \Okipa\LaravelTable\Result`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->result()->html(function($displayedList) {
    return $displayedList->sum('turnover');
});
```

### -&gt;classes()

[](#-classes-1)

> Override the default results classes and apply the given classes only on this result row.
> The default result classes are managed by the `config('laravel-table.classes.results')` value.

**Note :**

- Signature : `classes(array $classes): \Okipa\LaravelTable\Result`
- Optional

**Use case example :**

```
(new \Okipa\LaravelTable\Table)->result()->classes(['bg-dark', 'text-white', 'font-weight-bold']);
```

Tips
----

[](#tips)

- **Request :** No need to transmit the request to the table : it systematically uses the current request given by the `request()` helper to get the number of lines to show and the searching, sorting or pagination data. However, if you need to pass a particular request to the table, you can do it with the `->request()` method.
- **Column titles :** By default, the table columns titles take the following value : `__('validation.attributes.[databaseColumn])`. You can set a custom title using the `title()` method.
- **Columns displaying combination :** The following table column methods can be combined to display a result as wished. If you can't get the wanted result, you should use the `->html()` method to build a custom display.
    - `->button()`
    - `->link()`
    - `->icon()`
    - `->stringLimit()`
    - `->value()`

Usage examples
--------------

[](#usage-examples)

### Basic

[](#basic)

In your controller, simply call the package like the following example to generate your table :

```
$table = (new \Okipa\LaravelTable\Table)->model(\App\News::class)->routes(['index' => ['name' => 'news.index']]);
$table->column('title')->sortable()->searchable();
```

Then, send your `$table` object in your view and render your table like this :

```
{{ $table }}
```

That's it !

### Advanced

[](#advanced)

If you need your table for a more advanced usage, with a multilingual project for example, here is an example of what you can do in your controller :

```
$table = (new \Okipa\LaravelTable\Table)->model(\App\News::class)
    ->request($request)
    ->routes([
        'index'      => ['name' => 'news.index'],
        'create'     => ['name' => 'news.create'],
        'edit'       => ['name' => 'news.edit'],
        'destroy'    => ['name' => 'news.destroy'],
        'show'    => ['name' => 'news.show'],
    ])
    ->rowsNumber(50) // or set `false` to get all the items contained in database
    ->rowsNumberSelectionActivation(false)
    ->query(function ($query) use ($category_id) {
        // some examples of what you can do
        $query->select('news.*');
        // add a constraint
        $query->where('category_id', $category_id);
        // get value stored in a json field
        $query->addSelect('news.json_field->>json_attribute as json_attribute');
        // get a formatted value form a pivot table
        $query->selectRaw('count(comments.id) as comments_count');
        $query->leftJoin('news_commment', 'news_commment.news_id', '=', 'news.id');
        $query->leftJoin('comments', 'comments.id', '=', 'news_commment.comment_id');
        $query->groupBy('comments.id');
        // alias a value to make it available from the column model
        $query->addSelect('users.name as author');
        $query->join('users', 'users.id', '=', 'news.author_id');
    })
    ->disableRows(function($model){
        return $model->id === 1 || $model->id === 2;
    }, ['disabled', 'bg-secondary'])
    ->rowsConditionalClasses(function($model){
        return $model->id === 3;
    }, ['highlighted', 'bg-success']);
$table->column('image')->html(function ($model, $column) {
    return $model->{$column->databaseDefaultColumn}
        ? ''
        : null;
});
$table->column('title')->sortable()->searchable();
$table->column('content')->stringLimit(30);
$table->column('author')->sortable()->searchable('user', ['name']);
$table->column('category_id')
    ->title('Category custom name')
    ->icon('your-icon')
    ->button(['btn', 'btn-sm', 'btn-outline-primary'])
    ->value(function ($model, $column) {
        return config('news.category.' . $model->{$column->databaseDefaultColumn});
    });
$table->column()->link(function($model){
    return route('news.show', $model);
})->button(['btn', 'btn-sm', 'btn-primary']);
$table->column('released_at')->sortable()->dateTimeFormat('d/m/Y H:i:s');
$table->result()->title('Total of comments')->html(function($displayedList){
    return $displayedList->sum('comments_count');
});
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Arthur LORENT](https://github.com/okipa)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 62.1% 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 ~16 days

Recently: every ~39 days

Total

26

Last Release

2246d ago

PHP version history (3 changes)1.0.0PHP &gt;=7.1

1.0.12PHP ^7.2

1.2.4PHP ^7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/59102754?v=4)[Evgeniy Silantev](/maintainers/EvgeniySilantev)[@EvgeniySilantev](https://github.com/EvgeniySilantev)

---

Top Contributors

[![Okipa](https://avatars.githubusercontent.com/u/5328934?v=4)](https://github.com/Okipa "Okipa (18 commits)")[![EvgeniySilantev](https://avatars.githubusercontent.com/u/59102754?v=4)](https://github.com/EvgeniySilantev "EvgeniySilantev (7 commits)")[![TMigue](https://avatars.githubusercontent.com/u/7513794?v=4)](https://github.com/TMigue "TMigue (3 commits)")[![costeirs](https://avatars.githubusercontent.com/u/666358?v=4)](https://github.com/costeirs "costeirs (1 commits)")

---

Tags

phplaravelpackagegeneratorhtmllisttablegenerationgeneratetablesListsokipa

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[okipa/laravel-table

Generate tables from Eloquent models.

56752.8k](/packages/okipa-laravel-table)[okipa/laravel-form-components

Ready-to-use and customizable form components.

198.0k1](/packages/okipa-laravel-form-components)[tehwave/laravel-achievements

Simple, elegant Achievements the Laravel way

7012.8k](/packages/tehwave-laravel-achievements)[orchestra/html

HTML Component for Orchestra Platform

40112.6k2](/packages/orchestra-html)[wujunze/money-wrapper

MoneyPHP Wrapper

113.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

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