Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Table Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require ekyna/table
    

    Add the service provider to config/app.php:

    'providers' => [
        // ...
        Ekyna\Table\TableServiceProvider::class,
    ],
    
  2. 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]);
    }
    
  3. First View: Create a Blade template (resources/views/tables/users.blade.php):

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

First Use Case: Displaying Eloquent Results

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'));
}

Implementation Patterns

Data Binding

  • 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');
    

Column Customization

  • 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);
    

Pagination

$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.


Integration with Forms

  • Row Actions:
    $table->addRowAction('Edit', route('users.edit', $user->id), 'edit')
        ->addRowAction('Delete', route('users.destroy', $user->id), 'delete', ['method' => 'DELETE']);
    

Gotchas and Tips

Pitfalls

  1. Deprecated Package:

    • Last updated in 2015. Ensure compatibility with your Laravel version (likely works with Laravel 5.x).
    • No active maintenance; fork or extend if needed.
  2. No Built-in CRUD:

    • This is a read-only table component. For editable tables, consider pairing with a frontend framework (e.g., Vue/Alpine.js) or a package like yajra/laravel-datatables.
  3. Column Naming:

    • Column names must match the data keys exactly (case-sensitive). Use callbacks for transformations:
      $table->addColumn('user_name', 'Name', function ($value) {
          return $value['name']; // If data uses 'user_name' key
      });
      

Debugging

  • 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.


Extension Points

  1. Custom Styling: Override the default Blade template by publishing views:

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

    Then modify resources/views/vendor/table/.

  2. Add JavaScript: Extend functionality with client-side sorting/filtering by attaching scripts to the Blade template:

    {!! $table->render() !!}
    <script>
        // Custom JS logic
    </script>
    
  3. Fork and Update: Since the package is unmaintained, consider forking the GitHub repo to add features like:

    • Server-side processing (for large datasets).
    • Export to CSV/Excel.
    • Column visibility toggles.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core