ekyna/table
Ekyna Table is a small Laravel/PHP package for rendering and managing tabular data in your app. It provides helpers to define columns and rows, handle sorting and pagination, and generate table output for admin or back-office interfaces.
Installation:
composer require ekyna/table
Add the service provider to config/app.php:
'providers' => [
// ...
Ekyna\Table\TableServiceProvider::class,
],
Basic Usage: Register a table in a controller:
use Ekyna\Table\Table;
public function showTable()
{
$table = Table::make('users')
->addColumn('id', 'ID')
->addColumn('name', 'Name')
->addColumn('email', 'Email');
return view('tables.users', ['table' => $table]);
}
First View:
Create a Blade template (resources/views/tables/users.blade.php):
{!! $table->render() !!}
public function index()
{
$users = User::all();
$table = Table::make('users')
->setData($users)
->addColumn('id', 'ID')
->addColumn('name', 'Name')
->addColumn('email', 'Email')
->addColumn('created_at', 'Joined', function ($value) {
return $value->format('M d, Y');
});
return view('tables.users', compact('table'));
}
Eloquent Models:
$table = Table::make('users')
->setModel(User::class)
->addColumn('name', 'Name')
->addColumn('email', 'Email');
Automatically resolves columns from the model.
Array Data:
$data = [['id' => 1, 'name' => 'John'], ['id' => 2, 'name' 'Jane']];
$table = Table::make('custom')
->setData($data)
->addColumn('id', 'ID')
->addColumn('name', 'Name');
Callbacks for Dynamic Data:
$table->addColumn('status', 'Status', function ($value) {
return $value ? 'Active' : 'Inactive';
});
HTML Attributes:
$table->addColumn('name', 'Name')
->setAttribute('class', 'text-bold');
Sorting:
$table->addColumn('name', 'Name')
->setSortable(true);
$users = User::paginate(10);
$table = Table::make('users')
->setData($users)
->addColumn('id', 'ID')
->addColumn('name', 'Name');
return view('tables.users', compact('table'));
The package integrates with Laravel's pagination out of the box.
$table->addRowAction('Edit', route('users.edit', $user->id), 'edit')
->addRowAction('Delete', route('users.destroy', $user->id), 'delete', ['method' => 'DELETE']);
Deprecated Package:
No Built-in CRUD:
yajra/laravel-datatables.Column Naming:
$table->addColumn('user_name', 'Name', function ($value) {
return $value['name']; // If data uses 'user_name' key
});
Check Rendered HTML:
Use {{ dd($table->render()) }} to inspect the output for misconfigurations.
Data Validation:
Ensure setData() receives an iterable (e.g., Collection, array). Non-iterable data will break rendering.
Custom Styling: Override the default Blade template by publishing views:
php artisan vendor:publish --tag=table-views
Then modify resources/views/vendor/table/.
Add JavaScript: Extend functionality with client-side sorting/filtering by attaching scripts to the Blade template:
{!! $table->render() !!}
<script>
// Custom JS logic
</script>
Fork and Update: Since the package is unmaintained, consider forking the GitHub repo to add features like:
How can I help you explore Laravel packages today?