imer / laravel-query-table
Laravel plugin for displaying query results as a table with built-in filtering/sorting/pagination
Installs: 1 090
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=8.0.0
- illuminate/http: ^6|^7|^8|^9|^10
- illuminate/support: ^6|^7|^8|^9|^10
This package is auto-updated.
Last update: 2024-11-29 07:03:24 UTC
README
A laravel plugin for displaying query results as a table with built-in filtering/sorting/pagination.
Views use bootstrap and font-awesome, but can be published and modified via php artisan vendor:publish --provider="imer\QueryTable\QueryTableProvider"
command
While this package is still in early stages the api might still change for better usability
Example:
use imer\QueryTable; use imer\QueryTable\HtmlString; // ... $countries = ["de" => "Germany", "gb" => "United Kingdom", "us" => "United States"]; $customers = (new QueryTable($request, Customer::query())) ->addField( (new QueryTable\Field("customer_number")) ->sortable() ->filter(new QueryTable\TextFilter()) ->formatAsLink(function (Customer $r) { return route("customer.show", ["id" => $r->id]); }) ) ->addField( (new QueryTable\Field("company")) ->sortable() ->filter(new QueryTable\TextFilter()) ) ->addField((new QueryTable\Field("name"))->sortable()->filter(new QueryTable\TextFilter())) ->addField((new QueryTable\Field("email"))->sortable()->filter(new QueryTable\TextFilter())) ->addField( // Filter by yes/no (new QueryTable\Field("tax_exempt")) ->sortable() ->filter(new QueryTable\BoolFilter()) ->formatter(function ($v) { return $v ? trans("misc.yes") : trans("misc.no"); }) ) ->addField( // Country field with a dropdown filter (new QueryTable\Field("country")) ->sortable() ->filter(new QueryTable\DropdownFilter($countries)) ->formatter(function ($v) use ($countries) { return $countries[$v] ?? "n/a"; }) ) ->addField((new QueryTable\ViewField("customer._table_actions")) ->nameText(new HtmlString('<a href="' . e(route("customer.create")). '" class="btn btn-success"><i class="fa fa-plus"></i></a>'))); // pass $customers to your view and simply output the table: // {!! $customers !!}
Filter demo: https://github.com/imerr/laravel-query-table/assets/1426904/000197cf-09ff-41bc-acf6-eb01bd1a98e8