Configuration
The Eloquent Tables package provides several configuration options. To change these options, you should publish the config file.
Options
Theme
The theme option tells the package which frontend framework is used. This must be one of the
BrickNPC\EloquentTables\Enums\Theme enum options. For now, only Bootstrap 5 is supported.
<?php
// config/eloquent-tables.php
return [
// Other options
'theme' => BrickNPC\EloquentTables\Enums\Theme::Bootstrap5,
];
Data namespace
The Eloquent Tables package uses HTML data- attributes to store data inside HTML attributes. This data is used by the
JavaScript of the package. To avoid collisions with other libraries or your own data attributes, Eloquent Tables uses a
namespace for these data attributes. Configure this namespace here.
<?php
// config/eloquent-tables.php
return [
// Other options
'data-namespace' => 'et',
];
Search
When you add the searchable option to a column in your table, the table automatically displays a search bar at the top
of the table. The search config option defines configuration options for this search bar.
Query name
The query_name search option defines the key holding the search value. It is nested under the
table's name, so this sets the sub-key rather than the whole parameter: with the default, a table
named user reads ?user[search]=ada.
<?php
// config/eloquent-tables.php
return [
// Other options
'search' => [
'query_name' => 'search'
],
];
Sorting
When you add the sortable option to a column in your table, the table can be sorted by that column. The sorting
config option defines configuration options for this behavior.
Query name
The query_name sorting option defines the key holding the sort. It is nested under the
table's name, so this sets the sub-key rather than the whole parameter. The value is an array where
the keys are column names and the values are the direction, which is how you sort on multiple columns:
?user[sort][email]=asc&user[sort][name]=desc. The order of that array is the order the visitor clicked the headers,
and that is the order the sort is applied in.
<?php
// config/eloquent-tables.php
return [
// Other options
'sorting' => [
'query_name' => 'sort'
],
];
Filtering
When you define filters on your table, the table can be filtered based on those filters. The filtering config option
defines configuration options for this behavior.
Query name
The query_name filtering option defines the key holding the filters. It is nested under the
table's name, so this sets the sub-key rather than the whole parameter. The value is an array where
the keys are filter names and the values are the filter values, which is how you apply multiple filters at once:
?user[filter][active]=1.
<?php
// config/eloquent-tables.php
return [
// Other options
'filtering' => [
'query_name' => 'filter'
],
];
Pagination
The names of the page and per-page query parameters. Both are nested under the table's name, so these set the sub-key rather than the whole parameter.
'pagination' => [
'page_query_name' => 'page',
'per_page_query_name' => 'per_page',
],
Preferences
Whether a table remembers the per-page value and sort a visitor chose, and the cookie it stores them in. Enabled by default. See Saved preferences.
'preferences' => [
'enabled' => true,
'cookie_name' => 'eloquent_tables_preferences',
],
Icons
The Eloquent Tables package uses icons in a few places. To keep the icons consistent with your own style and icon library, you can configure the icons in the config. By default, the package uses UTF-8 characters or HTML Encoded entities.
These are the icons that are available:
| Icon name | Usage |
|---|---|
search | The search icon in the search bar |
sort-asc | The icon for sorting a table in ascending order |
sort-desc | The icon for sorting a table in descending order |
sort-none | The icon for when a column is sortable, but currently not sorted |
check | A checkmark used in boolean and checkmark type columns |
cross | A cross used in boolean and checkmark type columns. |
<?php
// config/eloquent-tables.php
return [
// Other options
'icons' => [
'search' => new HtmlString('🔎︎'),
'sort-asc' => '⭡',
'sort-desc' => '⭣',
'sort-none' => '⭥',
'check' => '✓',
'cross' => '✗',
],
];
Tables location
The tables-location option determines where the make table command will place the generated table classes. By
default, the command will place the table classes in the app/Tables directory.
<?php
// config/eloquent-tables.php
return [
// Other options
'tables-location' => 'Tables',
];
App configuration
Because the Eloquent Tables package is a Laravel package, there are a few Laravel configuration options that this package uses as well.
Locale
The built-in formatters need a locale to format things like dates and numbers. The Eloquent Tables package uses the
current locale of the application, which is usually set in the .env file as APP_LOCALE.
Timezone
The built-in date formatters also need a timezone to format dates. The Eloquent Tables package uses the current
timezone of the application, which is usually set in the app.php config file under the Application Timezone heading.
Decimals
This option is not a default Laravel configuration option, so you should add it yourself. The Eloquent Tables package
uses this option to format numbers. It is not required to add this option, but it is recommended to do so. Add a
decimals option to the app.php config file and set it to the default number of decimals you want to use when
formatting numbers.
Currency
This option is not a default Laravel configuration option, so you should add it yourself. The Eloquent Tables package
uses this option to format currency. It is not required to add this option, but it is recommended to do so.
Add a currency option to the app.php config file and set it to the currency you want to use when formatting
numbers as currency. The value should be a 3-letter ISO 4217 currency code indicating the currency to use.