Download the PHP package imcity-tech/laravel-translatable without Composer

On this page you can find all versions of the php package imcity-tech/laravel-translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-translatable

Laravel Translatable

This package is a fork of nevadskiy/laravel-translatable.

Tests Code Coverage License Latest Stable Version

The package provides possibility to translate your Eloquent models into different languages using a single database table.

🍬 Features

βš™οΈ Demo

βœ… Requirements

πŸ”Œ Installation

  1. Install the package via composer.

  2. Optional. If you are not going to use translations for models with UUID primary keys, make the following:
  1. Run the migration command.

πŸ”¨ Making models translatable

  1. Add the HasTranslations trait to your models which you want to make translatable.

  2. Add the $translatable array to your models with attributes you want to be translatable.

Final model may look like this

πŸ“„ Documentation

Default locale values are stored in the original table as usual.

Values in non-default locales of each translatable model are stored in the single translations table.

The package takes the default locale from the config('app.fallback_locale') value.

Automatically store and retrieve translations of the model using translatable attributes
Manually store and retrieve translations of the model
Methods for reading translation
Method Description
getTranslationOrDefault Retrieves a translation for the given attribute or a default value if a translation is missing.
getTranslation Retrieves a translation for the given attribute or null if a translation is missing.
getRawTranslation Retrieves a translation without any Eloquent accessors applied for the given attribute or null if a translation is missing.
getDefaultTranslation Retrieves the value in a default locale.
Translatable models creation

Note that translatable models will always be created in default locale even when the current locale is different. Any translations can be attached only to existing models.

Displaying collection of models

The package automatically eager loads translations of the current locale for you, so you can easily retrieve collection of models as usual.

Translations work with model accessors
Translations work with model mutators as well
Removing unused translations

The package automatically remove translations of deleted models respecting softDeletes, but if translatable models have been removed using query builder, their translations will exist in the database. To manually remove all unused translations, run the php artisan translatable:remove-unused command.

Querying models without translations

Sometimes you may need to query translatable model without the translations relation. You can do this using withoutTranslations scope.

Querying translations

You can execute queries on translatable models by translatable attributes.

It will also work with values in default locale.

If you want to query rows only by a specific locale, you should pass it by yourself.

$books = Book::whereTranslatable('title', 'Книга ΠΎ ΠΆΠΈΡ€Π°Ρ„Π°Ρ…', 'ru')->get();

Otherwise, the query builder will return matched rows within all available locales.

Also, you can use different operators for querying translations.

Ordering translations

Ordering models by a translatable attribute in the current locale.

Ordering models by a translatable attribute in the specific locale.

For more complex queries - feel free to use Laravel relation queries.

Disable auto loading

If you do not want to automatically load or save translations when you interact with a translatable property, you can disable the feature.

To disable it for a specific model, override the autoLoadTranslations or autoSaveTranslations methods in your model like so.

Or globally for every model.

Archiving translations

Sometimes it can be useful to archive some translations that will not be resolved automatically, but can be used for searching functionality. For example, you may store archived translation manually using the following code:

Now Old title is associated with a post that allows to find the post using whereTranslatable scope:

You can also pass null as a third argument to the archiveTranslation method when a locale is unknown. If you do not pass null, the current locale will be used instead.

Route model binding

Translatable model can be easily resolved using Route Model Binding feature.

All you need to do to let Laravel resolve models by a translatable attribute is to set the needed locale that you want to be used for querying models before a request will reach Illuminate\Routing\Middleware\SubstituteBindings::class middleware.

The simplest solution is to create a new middleware, for example SetLocaleMiddleware, attach it to the route where you want to resolve translatable models, and register the middleware in the $middlewarePriority array of the app/Http/Kernel.php file above the \Illuminate\Routing\Middleware\SubstituteBindings::class class.

It may look like this:

More about sorting middleware here.

Using morph map

It is recommended to use morph map for all translatable models to minimize coupling between a database and application structure.

More about morph maps here.

πŸ“‘ Changelog

Please see CHANGELOG for more information what has changed recently.

β˜• Contributing

Please see CONTRIBUTING for more information.

πŸ”“ Security

If you discover any security related issues, please e-mail me instead of using the issue tracker.

πŸ“œ License

The MIT License (MIT). Please see LICENSE for more information.


All versions of laravel-translatable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
laravel/framework Version ^9.0
imcity-tech/laravel-uuid Version ^0.8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package imcity-tech/laravel-translatable contains the following files

Loading the files please wait ....