Skip to content

luckykenlin/livewire-tables

Repository files navigation

livewire-tables

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A dynamic livewire table component for laravel.

Requirements

Installation

You can install the package via composer:

composer require luckykenlin/livewire-tables

Documentation

https://luckykenlin.github.io/livewire-tables/

Usage

Creating Tables

To create a table component you draw inspiration from the below stub:

php artisan make:table UsersTable

To specific model use --model:

php artisan make:table UsersTable --model=User
<?php

namespace App\Http\Livewire;

use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Luckykenlin\LivewireTables\Views\Action;
use Luckykenlin\LivewireTables\Views\Column;
use Luckykenlin\LivewireTables\LivewireTables;

class UsersTable extends LivewireTables
{
    public function query(): Builder
    {
        return User::query();
    }

    public function columns(): array
    {
        return [
            Column::make('#', 'id')->sortable(),
            Column::make('Name', 'name')->searchable()->sortable(),
            Column::make('Email', 'email')->searchable()->sortable(),

            Action::make()
        ];
    }
}

Your component must implement two methods:

/**
 * This defines the start of the query, usually Model::query() but can also eager load relationships and counts if needed.
 */
public function query() : Builder;

/**
 * This defines the columns of the table, they don't necessarily have to map to columns on the database table.
 */
public function columns() : array;

Rendering the Table

Place the following where you want the table to appear.

<livewire:users-table />

To-do/Roadmap

  • User Column Selection
  • Bulk Actions
  • Date Filter
  • Selector Filter
  • Multiple Selector Filter
  • Bulk Actions
  • CDN Css
  • Test Suite

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.