optimistdigital / nova-locale-field
A Laravel Nova field.
Installs: 257 197
Dependents: 3
Suggesters: 0
Security: 0
Stars: 17
Watchers: 3
Forks: 3
Open Issues: 18
Language:Vue
Requires
- php: >=7.1.0
- laravel/nova: ^2.0.11 || ^3.0
- dev-master
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/qs-and-express-6.11.0
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/terser-4.8.1
- dev-dependabot/npm_and_yarn/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/async-2.6.4
- dev-dependabot/npm_and_yarn/minimist-1.2.6
- dev-dependabot/npm_and_yarn/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/follow-redirects-1.14.8
- dev-dependabot/npm_and_yarn/nanoid-3.2.0
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/ws-7.4.6
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/browserslist-4.16.6
- dev-dependabot/npm_and_yarn/postcss-8.2.10
This package is auto-updated.
Last update: 2023-08-03 13:07:44 UTC
README
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:
composer require optimistdigital/nova-locale-field
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:
Schema::table('some_model_table', function ($table) { $table->string('locale'); $table->bigInteger('locale_parent_id')->nullable(); // Optionally, add a foreign key $table->foreign('locale_parent_id')->references('id')->on('some_model_table'); });
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. |
use OptimistDigital\NovaLocaleField\LocaleField; LocaleField::make('Locale', 'locale', 'locale_parent_id') ->locales(['en' => 'English', 'et' => 'Estonian']) // Optional when you've set a default ->maxLocalesOnIndex(4) // Optional, defaults to 4
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:
php artisan vendor:publish --provider="OptimistDigital\NovaLocaleField\FieldServiceProvider" --tag="config"
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.
use \OptimistDigital\NovaLocaleField\Filters\LocaleFilter; public function filters(Request $request) { return [ LocaleFilter::make('locale') ->locales(NovaEcommerce::getLocales()), // <- Optional // OR new LocaleFilter('locale'), ]; }
Credits
License
This project is open-sourced software licensed under the MIT license.