Download the PHP package okipa/laravel-bootstrap-table-list without Composer
On this page you can find all versions of the php package okipa/laravel-bootstrap-table-list. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-bootstrap-table-list
Laravel Bootstrap Table List
Because it is sometimes convenient to build a simple backoffice without sophisticated javascript treatments, Laravel Bootstrap Table List proposes a model-based and highly customizable php table list generation, that simply render your table HTML in your view, with a code-side-configuration.
:warning::warning::warning: This package has been replaced by https://github.com/Okipa/laravel-table. :warning::warning::warning:
:warning::warning::warning: Only bug fixes will be merged. Please consider moving to the new package. :warning::warning::warning:
Before use
This V2 of this table list generator is pre-configured for Bootstrap 4 and Fontawesome 5.
However, this package is deeply configurable and it is possible to easily set it up for Bootstrap 3 and other versions of FA or other icon libraries (or not icon at all).
If the configuration does not give enough possibilities for your customization needs, you definitely should publish the templates and customize them in your project.
Notes:
If someone is motivated to give me a functional configuration for bootstrap 3, I will include it in the readme. It could interest some developers.
Anyway, a pre-configured bootstrap 3 version of this package does exists (with less features) : please check the v1.
Installation
-
Install the package with composer :
-
Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider. If you don't use auto-discovery or if you use a Laravel 5.4- version, add the package service provider in the
register()
method from yourapp/Providers/AppServiceProvider.php
: - Load the package
CSS
orSASS
file from the[path/to/composer/vendor]/okipa/laravel-bootstrap-table-list/styles
directory to your project.
Package usage
Basic usage
In your controller, simply call the package like the following example to generate your table list :
Then, send your $table
object in your view and render your table list :
That's it !
Notes :
- Request : No need to transmit the request to the TableList : it systematically uses the current request given by the
request()
helper to get the number of lines to show and the searching, sorting or pagination data. However, if you need to pass a particular request to the TableList, you can do it with thesetRequest()
method. - Column titles : By default, the columns titles take the following value :
trans('validation.attributes.[attribute])
. You can set a custom title using thesetTitle()
method, especially when a a column is not related to a table attribute.
Advanced usage
If you need your table list for a more advanced usage, with a multilingual project for example, here is an example of what you can do in your controller :
API
TableList public methods
public function setModel(string $tableModel): \Okipa\LaravelBootstrapTableList\TableList
Set the model used for the table list generation (required).
public function setRequest(Request $request): \Okipa\LaravelBootstrapTableList\TableList
Set the request used for the table list generation (required).
public function setRoutes(array $routes): \Okipa\LaravelBootstrapTableList\TableList
Set the routes used for the table list generation (required) :
- Each route will be generated with the line entity id. The given extra parameters will be added for the route generation.
- The
index
route is required and must be the route that will be used to display the page that contains the table list. - The following routes can be defined as well :
create
: must be used to redirect toward the entity creation page. Displays aCreate
button under the table list if defined.edit
: must be used to redirect toward the entity edition page. Displays aEdit
icon on each table list line if defined.destroy
: must be used to destroy a table list line. Displays aRemove
icon on each table list line if defined.- Each route have to be defined with the following structure :
public function setRowsNumber(int $owsNumber): TableList
Set a custom number of rows for the table list (optional).
public function enableRowsNumberSelector(): TableList
Enables the rows number selection in the table list (optional) :
- Calling this method displays a rows number input that enable the user to choose how much rows to show.
public function addQueryInstructions(Closure $queryClosure): TableList
Set the query closure that will be used during the table list generation (optional).
For example, you can define your joined tables here.
The closure let you manipulate the following attribute : $query`.
public function disableLines(Closure $disableLinesClosure, array $lineClass = []): TableList
Set the disable lines closure that will be executed during the table list generation (optional).
The optional second param let you set the class that will be applied for the disabled lines.
By default, the config('tablelist.value.disabled_line.class')
config value is applied.
For example, you can disable the current logged user to prevent him being edited or deleted from the table list.
The closure let you manipulate the following attribute : $model.
public function highlightLines(Closure $highlightLinesClosure, array $lineClass = []): TableList
Set the highlight lines closure that will executed during the table list generation (optional).
The optional second param let you set the class that will be applied for the highlighted lines.
By default, the config('tablelist.value.highlighted_line.class')
config value is applied.
The closure let you manipulate the following attribute : $model.
public function addColumn(string $attribute = null) : TableList
Add a column that will be displayed in the table list (required) :
- At least one column must be added to the table list.
- A column can be created without attribute specification, in case of HTML element display, for example.
TableListColumn public methods
public function setTitle(string $title): TableListColumn
Set the column title (optional).
public function sortByDefault(string $direction = 'asc'): TableListColumn
Set the default sorted column (required).
public function useForDestroyConfirmation(): TableListColumn
Use the column attribute for the destroy confirmation message generation (required) :
- At least one column must be selected for destroy confirmation if a destroy route is set.
- This method can be called only once.
public function isSortable(): TableListColumn
Make the column sortable (optional).
public function isSearchable(): TableListColumn
Make the column searchable (optional).
public function setCustomTable(string $customColumnTable, string $customColumnTableRealAttribute = null): TableListColumn
Define the custom related table for the column attribute (optional).
Defining the custom related table becomes mandatory if you define your column as searchable and if the column attribute does not directly belong to the table list model table.
The custom real attribute will only be used for the sql request and will also be required only if the defined column attribute does not directly exist in the defined custom table.
Examples :
public function setColumnDateTimeFormat(string $columnDateFormat): TableListColumn
Set the format for a datetime, date or time attribute (optional).
(Carbon::parse($value)->format($format) method is used under the hood).
public function isButton(array $buttonClass = []): TableListColumn
Set the column button class (optional).
The attribute is wrapped into a button.
public function setIcon(string $icon, $showWithNoValue = false): TableListColumn
Set the icon to display before the value (optional).
public function setStringLimit(int $stringLimit): TableListColumn
Set the string value display limitation (optional).
Shows "..." when the limit is reached....ravel-bootstrap-table-list/src/Traits/RoutesValidationChecks.php
public function isLink($url = null): TableListColumn
Set the link url.
You can declare the link as a string or as a closure which will let you manipulate the following attributes : $entity, $column.
If no url is declared, it will be set with the column value.
public function isCustomValue(Closure $customValueClosure): TableListColumn
Set a custom value in the method closure (optional).
The closure let you manipulate the following attributes : $entity, $column.
public function isCustomHtmlElement(Closure $customHtmlEltClosure): TableListColumn
Set the HTML element to render in the method closure (optional).
The closure let you manipulate the following attributes : $entity, $column.
Configurations
To personalize the package configuration, you have to publish it first with the following script :
Then, open the published package configuration file (config/tablelist.php
) and override the default table list configuration by setting your own values.
Customize translations
You can customize the table list associated translation by publishing them in your project :
Once you have published them, You will find them in your resources/lang
directory.
Customize templates
Publish the package blade templates file in your project :
Then, change the content from the package templates in your resources/views/vendor/tablelist
directory.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributors
License
The MIT License (MIT). Please see License File for more information.