Download the PHP package optimistdigital/nova-locale-field without Composer
On this page you can find all versions of the php package optimistdigital/nova-locale-field. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download optimistdigital/nova-locale-field
More information about optimistdigital/nova-locale-field
Files in optimistdigital/nova-locale-field
Package nova-locale-field
Short Description A Laravel Nova field.
License MIT
Informations about the package nova-locale-field
Nova Locale Field
This package has been deprecated in favour of Nova Translatable
This Laravel Nova package allows you to manage multiple localisations of a model.
Screenshots
Installation
Install the package in a Laravel Nova project via Composer:
Usage
Preparing the models and database
This field requires a few database changes - namely, the model requires two new columns: one for the locale and one to reference the locale parent model.
You can set the column names to anything you want. The column names are passed to the field when creating it.
Column | Suggested name | Type (MySQL / Eloquent) | Nullable | Example value | Description |
---|---|---|---|---|---|
Locale | locale |
VARCHAR / string |
NO | en_US |
A text column for the locale, maximum size depends on which types of locales you use (ie en vs en_US ). |
Locale parent ID | locale_parent_id |
BIGINT / bigInteger |
YES | 1 |
A locale parent reference column (foreign key, though the actual foreign key is optional) |
Example migration:
Creating the field
This field has slightly different constructor (::make()
) arguments than other Nova fields.
# | Argument | Type | Description |
---|---|---|---|
1 | \$name | string | Display name of the field, visible to the user as the column title in the index field and as the name of the locale selection field. |
2 | \$localeAttribute | string | The attribute (column) name of the locale value. |
3 | \$localeParentAttribute | string | The attribute (column) name for the locale parent id. |
Options
Possible options you can pass to the field using the option name as a function, ie ->maxLocalesOnIndex(4)
.
Option | Type | Default | Description |
---|---|---|---|
locales |
array | [] | Locales in an array as key-value pairs (['id' => 'value'] ). |
maxLocalesOnIndex |
int | 4 | The amount of locales shown on the index view. If this is exceeded, the locales are only visible on the detail view. |
Configuration
Config file
You can publish the config file and edit the default values (besides locales) there.
To publish the configuration file, run the following artisan publish command:
Default locales
The default locales can be defined in the config file via a closure or an array.
This default value can be overriden on a per-field basis using the ->locales([])
function directly on the field.
Filters
The package also provides a select type filter for the locales.
Using the locale filter
To use the locale filter, just add it to the array your resources' filters()
function returns. Pass in the name of the locale field as the only argument in the constructor
or the static make
function.
You can also override the default displayed locale options by calling ->locales([])
on the filter. This is optional and the filter will use the default locales when not set.
Credits
License
This project is open-sourced software licensed under the MIT license.