Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

laravel-table

> 前端框架
Open source

Generate tables from Eloquent models.

571 stars0 likes1 views
WebsiteGitHub

About

Generate tables from Eloquent models.

Package looking for co-maintainers

I've been quite busy professionally lately and I'm currently looking for one or more co-maintainers to help me to maintain and develop this package.

Current roadmap:

  • PR reviewing
  • Tailwind 3 compatibility

Please contact me at arthur[dot]lorent[at]gmail.com to apply.


Save time and easily render tables in your views from Eloquent models.

Tables can be generated under the following UI frameworks:

  • Bootstrap 5
  • Bootstrap 4
  • TailwindCSS 3 (upcoming feature)

Found this package helpful? Please consider supporting my work!

Compatibility

Laravel version Livewire version PHP version Package version
^9.0 | ^10.0 ^2.0 8.1.* | 8.2.* ^5.3
^8.0 | ^9.0 ^2.0 ^8.1 ^5.0
^7.0 | ^8.0 X ^7.4 | ^8.0 ^4.0
^7.0 | ^8.0 X ^7.4 | ^8.0 ^3.0
^6.0 | ^7.0 X ^7.4 | ^8.0 ^2.0
^5.8 | ^6.0 | ^7.0 X ^7.2 | ^7.3 | ^7.4 ^1.3
^5.5 | ^5.6 | ^5.7 | ^5.8 | ^6.0 X ^5.8 | ^7.1 ^1.0

Upgrade guide

  • From Livewire2 to Livewire3
  • From V4 to V5
  • From V3 to V4
  • From V2 to V3
  • From V1 to V2

Usage

Create your table with the following command:

bash
php artisan make:table UsersTable --model=App/Models/User

Configure your table in the UsersTable generated class, which can be found in the app\Tables directory:

…

And display it in a view:

blade

Table of contents

  • Installation
  • Configuration
  • Templates
  • Translations
  • How to
    • Create table configuration
    • Display tables in views
    • Pass external data to your tables
    • Generate tables from Eloquent models
    • Override native selects behaviour on your tables
    • Add query instructions on tables
    • Handle tables number of rows per page, pagination and navigation status
    • Set conditional row class
    • Setup table filters
    • Define table head action
    • Define table bulk actions
    • Define table row actions
    • Declare columns on tables
    • Format column values
    • Define column actions
    • Configure columns searching
    • Configure columns sorting
    • Allow columns to be reordered from drag and drop action
    • Declare results on tables
    • Set up a few lines of JavaScript
    • Trigger Livewire events on table load
    • Interact with your tables from events
  • Testing
  • Changelog
  • Contributing
  • Credits
  • Licence

Installation

  • Install the package with composer:
bash
composer require okipa/laravel-table

This package uses Livewire under the hood and its installation is required.

You'll have to follow the installation instructions if Livewire is not already installed on your project.

Configuration

Optionally publish the package configuration:

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

Templates

Optionally publish the package templates:

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

Translations

All words and sentences used in this package are translatable.

See how to translate them on the Laravel official documentation: https://laravel.com/docs/localization#using-translation-strings-as-keys.

Here is the list of the words and sentences available for translation:

Status

  • Loading in progress...
  • No results were found.
  • You can rearrange the order of the items in this list using a drag and drop action.
  • Reset filters
  • Yes
  • No
  • Search by:
  • Reset research
  • Number of rows per page
  • Sort ascending
  • Sort descending
  • Actions
  • Bulk Actions
  • Create
  • Add
  • Show
  • Edit
  • Destroy
  • Activate
  • Deactivate
  • Verify Email
  • Unverify Email
  • Toggle On
  • Toggle Off
  • Are you sure you want to execute the action :action on the line #:primary?
  • Are you sure you want to execute the action :action on the field :attribute from the line #:primary?
  • Are you sure you want to execute the action :action on the :count selected lines?
  • The line #:primary does not allow the action :action and will not be affected.
  • :count selected lines do not allow the action :action and will not be affected.
  • The action :action has been executed on the line #:primary.
  • The action :action has been executed on the field :attribute from the line #:primary.
  • The action :action has been executed on the :count selected lines.
  • The line #:primary does not allow the action :action and was not affected.
  • :count selected lines do not allow the action :action and were not affected.
  • The list has been reordered.
  • Showing results :start to :stop on :total

How to

Create table configurations

Generate a table configuration by executing this command : php artisan make:table UsersTable.

If you want to generate a configuration with a predefined model, just add this option at the end: --model=App/Models/User.

You'll find all your generated table configurations in the app/Tables directory.

Display tables in views

Just call this Livewire component in your view with your configuration class name passed in the config parameter.

blade

Pass external data to your tables

In case you have specific attributes to transmit to your table configuration, you should pass them to the configParams parameter.

This could be useful when you have to transmit external information to your table.

blade
 1]"/>

You should then declare the passed attributes as public attributes your table configuration.

php
namespace App\Tables;

use App\Models\User;
use Okipa\LaravelTable\Table;
use Okipa\LaravelTable\Abstracts\AbstractTableConfiguration;

class UsersTable extends AbstractTableConfiguration
{
    // You will now be able to use the provided `$this->categoryId` category ID in your table configuration.
    public int $categoryId;

    // ...
}

Generate tables from Eloquent models

To generate a table from an Eloquent model, you'll just have to call the model method on your table.

php
namespace App\Tables;

use App\Models\User;
use Okipa\LaravelTable\Table;
use Okipa\LaravelTable\Abstracts\AbstractTableConfiguration;

class UsersTable extends AbstractTableConfiguration
{
    protected function table(): Table
    {
        return Table::make()->model(User::class);
    }
}

Override native selects behaviour on your tables

You may want to override native HTML select components behaviour on your tables.

You will be able to add a data attribute (which is known as the best practice to add extra features to a HTML component) to all the HTML select components displayed on your tables by defining an array of HTML attribute as value for the laravel-table.html_select_components_attributes config key.

php
// `data-selector` HTML attribute will be appended to all tables HTML select components.
'html_select_components_attributes' => ['data-selector' => true],

Add query instructions on tables

To add specific query instructions on tables, use the available query method.

You'll be able to set specific Eloquent instructions by passing a closure parameter to the query method on your table.

This closure will allow you to manipulate a \Illuminate\Database\Eloquent\Builder $query argument.

php
namespace App\Tables;

use App\Models\User;
use Okipa\LaravelTable\Table;
use Illuminate\Database\Eloquent\Builder;
use Okipa\LaravelTable\Abstracts\AbstractTableConfiguration;

class UsersTable extends AbstractTableConfiguration
{
    protected function table(): Table
    {
        return Table::make()
            ->model(User::class)
            ->query(fn(Builder $query) => $query->where('category_id', 1));
    }   
}

Handle tables number of rows per page, pagination and navigation status

You have two ways to allow or disallow users to choose the number of rows that will be displayed per page:

  • Activate or deactivate it globally from the laravel-table.enable_number_of_rows_per_page_choice config boolean value
  • Override global activation status by executing the enableNumberOfRowsPerPageChoice() method on your table
php
namespace App\Tables;

use App\Models\User;
use Okipa\LaravelTable\Table;
use Okipa\LaravelTable\Abstracts\AbstractTableConfiguration;

class UsersTable extends AbstractTableConfiguration
{
    protected function table(): Table
    {
        return Table::make()
            ->model(User::class)
            ->enableNumberOfRowsPerPageChoice(false);
    }
}

Following the same logic, you'll be able to define the number of rows per page options that will be available for selection:

  • Set options globally from the laravel-table.number_of_rows_per_page_default_options config array value
  • Override global options by executing the numberOfRowsPerPageOptions() method on your table

The first available option will be automatically selected and applied on table initialization.

php
namespace App\Tables;

use App\Models\User;
use Okipa\LaravelTable\Table;
use Okipa\LaravelTable\Abstracts\AbstractTableConfiguration;

class UsersTable extends AbstractTableConfiguration
{
    protected function table(): Table
    {
        return Table::make()
            ->model(User::class)
            // Table will display 5 rows on initialization and will allow displaying 10, 15, 20 or 25 rows.
            ->numberOfRowsPerPageOptions([5, 10, 15, 20, 25]);
    }
}

Pagination will automatically be handled, according to the number of rows to display and the total number of rows, as well as a navigation status.

Both of them will be displayed in the table footer.

Set conditional row class

Define conditional row class on tables by passing a closure argument to the rowClass method.

This closure will allow you to manipulate a Illuminate\Database\Eloquent $model argument and has to return an array of classes where the array key contains the class or classes you wish to add, while the value is a boolean expression.

php
namespace App\Tables;

use App\Models\User;
use Okipa\

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPgenerategenerationgeneratorhtml

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架