Installation &amp; setup | laravel-translatable | Spatie

 SPATIE

  Laravel Translatable
=======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-translatable](https://spatie.be/docs/laravel-translatable/v6)  Installation &amp; setup

 Version   v6

 Other versions for crawler [v6](https://spatie.be/docs/laravel-translatable/v6)

- [ Introduction ](https://spatie.be/docs/laravel-translatable/v6/introduction)
- [ Support us ](https://spatie.be/docs/laravel-translatable/v6/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-translatable/v6/requirements)
- [ Upgrading ](https://spatie.be/docs/laravel-translatable/v6/upgrading)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-translatable/v6/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-translatable/v6/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-translatable/v6/changelog)
- [ About us ](https://spatie.be/docs/laravel-translatable/v6/about-us)

Basic usage
-----------

- [ Getting and setting translations ](https://spatie.be/docs/laravel-translatable/v6/basic-usage/getting-and-settings-translations)
- [ Removing translations ](https://spatie.be/docs/laravel-translatable/v6/basic-usage/removing-translations)
- [ Replacing translations ](https://spatie.be/docs/laravel-translatable/v6/basic-usage/replacing-translations)
- [ Querying translations ](https://spatie.be/docs/laravel-translatable/v6/basic-usage/querying-translations)
- [ Validation translations ](https://spatie.be/docs/laravel-translatable/v6/basic-usage/validating-translations)
- [ Handling missing translations ](https://spatie.be/docs/laravel-translatable/v6/basic-usage/handling-missing-translations)

Advanced usage
--------------

- [ Available events ](https://spatie.be/docs/laravel-translatable/v6/advanced-usage/available-events)
- [ Customize the toArray method ](https://spatie.be/docs/laravel-translatable/v6/advanced-usage/customize-the-toarray-method)
- [ Usage with factories ](https://spatie.be/docs/laravel-translatable/v6/advanced-usage/usage-with-factories)

 Installation &amp; setup
========================

###  On this page

1. [ Making a model translatable ](#content-making-a-model-translatable)

You can install the package via composer:

```
composer require spatie/laravel-translatable
```

Making a model translatable
-----------------------------------------------------------------------------------------------------------------------------------------

The required steps to make a model translatable are:

- First, you need to add the `Spatie\Translatable\HasTranslations`-trait.
- Next, you should create a public property `$translatable` which holds an array with all the names of attributes you wish to make translatable.
- Finally, you should make sure that all translatable attributes are set to the `json`-datatype in your database. If your database doesn't support `json`-columns, use `text`.

Here's an example of a prepared model:

```
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class NewsItem extends Model
{
    use HasTranslations;

    public array $translatable = ['name'];
}
```
