Download the PHP package okipa/laravel-table without Composer

On this page you can find all versions of the php package okipa/laravel-table. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-table

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:

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


Latest Stable Version Total Downloads Build Status Coverage Status License: MIT

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

Tables can be generated under the following UI frameworks:

Found this package helpful? Please consider supporting my work!

Donate Donate

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

Usage

Create your table with the following command:

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

And display it in a view:

Table of contents

Installation

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:

Templates

Optionally publish the package templates:

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

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.

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.

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

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.

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.

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.

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:

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

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

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.

Setup table filters

Configuring table filters will make them appear as select HTML components on a dedicated bar above the table.

The filters bar will not appear if no filter is declared.

This package provides the following built-in filters:

To use them, you'll have to pass an array to the filters method, containing the filter instances to declare.

You may need to create your own filters. To do so, execute the following command: php artisan make:table:filter MyNewFilter.

You'll find your generated table filter in the app/Tables/Filters directory.

You will now be able to use your new filter in your tables.

Define table head action

Configure a table action that will be displayed as a button positioned at the right of the table head.

If no head action is declared, the dedicated slot for it in the table head will remain empty.

This package provides the following built-in head actions:

To use one of them, you'll have to pass an instance of it to the headAction method.

You'll be able to chain the following method to your head action:

You may need to create your own head actions. To do so, execute the following command: php artisan make:table:head:action MyNewHeadAction.

You'll find your generated table head action in the app/Tables/HeadActions directory.

You will now be able to use your new head action in your tables.

Define table bulk actions

Configure table bulk actions that will be available in a dropdown positioned at the left of the table head.

If no bulk action is declared on your table, the dedicated column will not be displayed.

Important note: you'll have to set up a few lines of javascript to allow bulk actions confirmation requests and feedback to be working properly.

This package provides the built-in following bulk actions:

To use them, you'll have to pass a closure parameter to the bulkActions method. This closure will allow you to manipulate a Illuminate\Database\Eloquent $model argument and has to return an array containing bulk action instances.

You'll be able to chain the following methods to your bulk actions:

You may need to create your own bulk actions. To do so, execute the following command: php artisan make:table:bulk:action MyNewBulkAction.

You'll find your generated table bulk actions in the app/Tables/BulkActions directory.

You will now be able to use your new bulk action in your tables.

Define table row actions

Configure row actions on your table that will be displayed at the end of each row.

If no row action is declared on your table, the dedicated Actions column at the right of the table will not be displayed.

Important note: you'll have to set up a few lines of javascript to allow row actions confirmation requests and feedback to be working properly.

This package provides the built-in following row actions:

To use them, you'll have to pass a closure parameter to the rowActions method. This closure will allow you to manipulate a Illuminate\Database\Eloquent $model argument and has to return an array containing row action instances.

You'll be able to chain the same methods as for a bulk action => See bulk actions configuration.

You may need to create your own row actions. To do so, execute the following command: php artisan make:table:row:action MyNewRowAction.

You'll find your generated table row actions in the app/Tables/RowActions directory.

You will now be able to use your new row action in your tables.

You may need your row actions to be confirmed before they'll be executed and to trigger feedback messages.

You'll have to configure them in the same way you did for bulk actions.

Declare columns on tables

Declare columns on tables with the columns method available in your generated table configuration, from which you'll have to return an array of column instances.

To declare columns, just use the static make method that will await a string $attribute argument. This attribute will be used to get the default cell value.

By default, the column title will be defined to __('validation.attributes.<attribute>') in order to reuse attributes translations.

If you need to, you may use the title method that will await a string $title argument to set a specific column title that will override the default one.

Format column values

You'll sometimes need to apply specific formatting for your columns. There are a few ways to achieve this.

For specific cases, you should pass a closure parameter to the format method on your column.

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

If you want to apply the same formatting treatment repeatedly, you should create a formatter with the following command: php artisan make:table:formatter NewFormatter.

You'll find the generated formatter in the app\Table\Formatters directory.

You'll be able to reuse this formatter in your tables.

This package provides the following built-in formatters :

Define column actions

Configure column actions on your table that will be displayed on their own cells.

Column actions have a lot in common with row actions.

Important note: you'll have to set up a few lines of javascript to allow column actions confirmation requests and feedback to be working properly.

This package provides the built-in following actions:

To use them, you'll have to pass a closure parameter to the action method. This closure will allow you to manipulate a Illuminate\Database\Eloquent $model argument and has to return an AbstractColumnAction instance.

You'll be able to chain the same methods as for a bulk action => See bulk actions configuration.

You may need to create your own column actions. To do so, execute the following command: php artisan make:table:column:action MyNewColumnAction.

You'll find your generated table column actions in the app/Tables/ColumnActions directory.

You will now be able to use your new column action in your tables.

You may need your column actions to be confirmed before they'll be executed and to trigger feedback messages.

You'll have to configure them in the same way you did for bulk actions.

Configure columns searching

Allow searching on columns by calling the searching method.

When searchable fields are set, a search input will appear in the table head.

Searchable column titles will be used to indicate which field can be searched on the search input placeholder.

By default, searching will be applied to columns defined keys.

You will be able to set up a custom searching behaviour by passing a closure to the searchable method.

This closure will be executed when searching will be triggered on the table and will allow you to manipulate a Illuminate\Database\Eloquent\Builder $query argument.

Configure columns sorting

Allow sorting on columns by calling the sortable method.

Sortable columns will display clickable sort icons before their titles that will trigger ascending or descending sorting.

By default, sorting will be applied to columns defined keys.

To sort a column by default, use the sortByDefault column method, which will allow you to pass a string $direction argument.

You can sort by default a column that is not sortable.

You will be able to set up a custom sorting behaviour by passing a closure to the sortable method.

This closure will be executed when sorting will be triggered on the column and will allow you to manipulate a Illuminate\Database\Eloquent\Builder $query and a string $sortDir arguments (asc or desc).

Allow columns to be reordered from drag and drop action

Allow columns to be reordered from drag and drop action by calling the reorderable method on your table.

This method will await a first string $attribute argument, an optional second string $title argument, and an optional third string $sortDirByDefault argument (accepting asc or desc values).

Important notes:

Activating this feature will:

Tip: if you are using packages like spatie/eloquent-sortable to handle your Eloquent models sorting behaviour with a grouping query, you'll have to also set this grouping query in the table query instruction.

Declare results on tables

To display results, you'll have to return an array of result instances from the results method available in your generated table configuration.

If no result is declared, their dedicated space will remain empty.

Results should be declared this way:

  1. Create a Result instance with the static make method
  2. Chain the title method that will await a string $title argument
  3. Chain the format method that will await a closure, letting you manipulate Illuminate\Database\Query\Builder $totalRowsQuery and Illuminate\Support\Collection $displayedRowsCollection params

Set up a few lines of JavaScript

You'll have to add few Javascript lines to your project once this package is installed, in order to allow confirmation requests and actions feedback to be working properly.

When an action is requesting the user confirmation, it will not be directly executed. A table:action:confirm Livewire event will be emitted instead with the following parameters:

  1. The action type
  2. The action identifier
  3. The model primary key related to your action
  4. The $confirmationQuestion attribute from your action

As you will see on the provided snippet below, the 4th param of this event is the only one you'll have to use in order to request the user confirmation. The 3 first params are only there to be sent back to a new event when the action is confirmed by the user. Just ignore them in your treatment.

You will have to intercept this event from your own JS script and prompt a confirmation request.

When the action is confirmed by the user, you'll have to emit a new laraveltable:action:confirmed Livewire event that will trigger the action execution. You'll have to pass it the 3 first arguments provided in the table:action:confirm event:

  1. The action type
  2. The action identifier
  3. The model primary key related to your action

Here is an JS snippet to show you how to proceed:

Once an action is executed, a table:action:feedback Livewire event is triggered (it sometimes depends on the configuration of a feedback message).

Following the same logic, you'll have to intercept it from a JS script as shown on the snippet below to provide an immediate feedback to the user:

Finally, in order to allow head RedirectHeadAction and CreateHeadAction to open link in new tab, you'll also have to add the following JS snippet:

Trigger Livewire events on table load

You may want to trigger some events on table load, in order to load UI third party JS libraries for example.

You can do it using the table emitEventsOnLoad method, that will await an array of events.

Interact with your tables from events

You will be able to interact with your tables by sending them the following Livewire events:

Testing

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Credits

License

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


All versions of laravel-table with dependencies

PHP Build Version
Package Version
Requires php Version 8.1.*|8.2.*
illuminate/contracts Version ^9.0|^10.0
livewire/livewire Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package okipa/laravel-table contains the following files

Loading the files please wait ....