Courses

Multi-Language Laravel 11: All You Need to Know

astrotomic/laravel-translatable

Summary of this lesson:
- Use separate translation table for each model
- Create parent and translation models
- Configure translatable attributes
- Handle translations with more complex database structure
- Use unique syntax for retrieving translations by locale

This package relies on a separate DB table to contain all of your localized model information. You will have to manually create this table and add the necessary columns. The package will then automatically handle the rest.

In other words, it requires more setup initially but provides a lot of flexibility.


Installation

In the full installation guide we can quickly spot that it's not too complicated to install this package:

Installing package via composer:

composer require astrotomic/laravel-translatable

Publishing the config file:

php artisan vendor:publish --tag=translatable

Adapting the configuration file to our case:

'locales' => [
'en',
'es',
],

This will set the base up for us to use.


Usage

After the initial setup, we have to adapt our Models to use the translation, which will require quite a bit of coding (but it's not too complicated).

Use this package, the biggest difference is in Migrations and Models:...

The full lesson is only for Premium Members.
Want to access all 18 lessons of this course? (80 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord