PHPackages                             optimistdigital/nova-locale-field - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. optimistdigital/nova-locale-field

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

optimistdigital/nova-locale-field
=================================

A Laravel Nova field.

2.0.14(5y ago)17281.7k↑32.8%7[16 PRs](https://github.com/outl1ne/nova-locale-field/pulls)3MITVuePHP &gt;=7.1.0

Since May 30Pushed 2y ago2 watchersCompare

[ Source](https://github.com/outl1ne/nova-locale-field)[ Packagist](https://packagist.org/packages/optimistdigital/nova-locale-field)[ RSS](/packages/optimistdigital-nova-locale-field/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (40)Used By (3)

Nova Locale Field
=================

[](#nova-locale-field)

### This package has been deprecated in favour of [Nova Translatable](https://github.com/outl1ne/nova-translatable)

[](#this-package-has-been-deprecated-in-favour-of-nova-translatable)

This [Laravel Nova](https://nova.laravel.com) package allows you to manage multiple localisations of a model.

Screenshots
-----------

[](#screenshots)

[![Detail View](docs/detail.png)](docs/detail.png)

[![Form View](docs/form.png)](docs/form.png)

[![Index View](docs/index.png)](docs/index.png)

Installation
------------

[](#installation)

Install the package in a Laravel Nova project via Composer:

```
composer require optimistdigital/nova-locale-field
```

Usage
-----

[](#usage)

### Preparing the models and database

[](#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.

ColumnSuggested nameType (MySQL / Eloquent)NullableExample valueDescriptionLocale`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

[](#creating-the-field)

This field has slightly different constructor (`::make()`) arguments than other Nova fields.

\#ArgumentTypeDescription1$namestringDisplay 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$localeAttributestringThe attribute (column) name of the locale value.3$localeParentAttributestringThe 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
-------

[](#options)

Possible options you can pass to the field using the option name as a function, ie `->maxLocalesOnIndex(4)`.

OptionTypeDefaultDescription`locales`array\[\]Locales in an array as key-value pairs (`['id' => 'value']`).`maxLocalesOnIndex`int4The amount of locales shown on the index view. If this is exceeded, the locales are only visible on the detail view.Configuration
-------------

[](#configuration)

### Config file

[](#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

[](#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
-------

[](#filters)

The package also provides a select type filter for the locales.

### Using the locale filter

[](#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()), //
