novius/laravel-nova-translatable
Laravel Nova Translatable
Introduction
This package allows you to manage Laravel Models which use Laravel Translatable in Laravel Nova.
Requirements
- Laravel Nova >= 4.0
- Laravel >= 10.0
- PHP >= 8.2
- Laravel Translatable >= 2.0
NOTE: These instructions are for Laravel >= 10.0 and PHP >= 8.2 If you are using prior version, please see the previous version's docs.
Installation
You can install the package via composer:
composer require novius/laravel-nova-translatable
Assets
Next, we need to publish the package's assets. We do this by running the following command:
php artisan vendor:publish --provider="Novius\LaravelNovaTranslatable\LaravelNovaTranslatableServiceProvider" --tag="public"
Fields, Action, Filter, Card
- Add
Localefield on your Nova Resource. - Add
Translationsfield on your Nova Resource. Don't forget to add relationtranslationsin the eager loading of your resource. You can translate item from the list of flags displayed. - You can add the
LocaleFilterfilter on your Nova Resource. - You can add the
Localescard on your Nova Resource, if you've added theLocaleFilter.
use Laravel\Nova\Resource;
use Novius\LaravelNovaTranslatable\Nova\Actions\Translate;
class Post extends Resource
{
// If your model uses the SoftDelete trait
// public static $with = ['translationsWithDeleted'];
// Otherwise
public static $with = ['translations'];
public function fields(NovaRequest $request): array
{
return [
Locale::make(),
Translations::make(),
];
}
// Optional, if you want to have a bar to switch locale of the items displayed on the index, more accessible than the filters
// work with the filter LocaleFilter
public function cards(NovaRequest $request): array
{
return [
new Locales(),
];
}
public function filters(NovaRequest $request): array
{
return [
new LocaleFilter(),
];
}
// Optional, if you want to implement custom translation on your model
public function translate(): void
{
$model = $this->model();
$model->attribute_to_translate = 'Translation';
}
Lang files
If you want to customize the lang files, you can publish them with:
php artisan vendor:publish --provider="Novius\LaravelNovaTranslatable\LaravelNovaTranslatableServiceProvider" --tag="lang"
Lint
Lint your code with Laravel Pint using:
composer run-script lint
Licence
This package is under GNU Affero General Public License v3 or (at your option) any later version.
Related Packages
Add translation to your Nova Resources. The translations will be stored in a tra...
A Laravel Nova field container allowing to depend on other fields values
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 2.0.3 | >=8.2 | ^10.0 | | AGPL-3.0-or-later | |
| 2.0.2 | >=8.2 | ^10.0| | AGPL-3.0-or-later | |
| 2.0.1 | >=8.2 | ^10.0| | AGPL-3.0-or-later | |
| 2.0.0 | >=8.2 | ^10.0| | AGPL-3.0-or-later | |
| 1.1.0 | >=8.2 | ^10.0| | AGPL-3.0-or-later | |
| 1.0.3 | >=8.2 | ^10.0| | AGPL-3.0-or-later | |
| 1.0.2 | >=8.2 | ^10.0| | AGPL-3.0-or-later | |
| 1.0.1 | >=8.2 | ^10.0| | AGPL-3.0-or-later | |
| 1.0.0 | >=8.2 | ^10.0| | AGPL-3.0-or-later | |
| 0.0.5 | ^8.1 | ^8.83.4| | AGPL-3.0-or-later | |
| 0.0.4 | ^8.1 | ^8.83.4| | AGPL-3.0-or-later | |
| 0.0.3 | ^8.1 | ^8.83.4| | AGPL-3.0-or-later | |
| 0.0.2 | ^8.1 | ^8.83.4| | AGPL-3.0-or-later | |
| 0.0.1 | ^8.1 | ^8.83.4| | AGPL-3.0-or-later |