Download the PHP package esign/laravel-helpermodel-translatable without Composer

On this page you can find all versions of the php package esign/laravel-helpermodel-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-helpermodel-translatable

Make Eloquent models translatable

Latest Version on Packagist Total Downloads GitHub Actions

This package allows you to make eloquent models translatable by using a seperate model for storing translations, e.g. Post and PostTranslation.

Installation

You can install the package via composer:

The package will automatically register a service provider.

Next up, you can publish the configuration file:

The config file will be published as config/helpermodel-translatable.php with the following content:

Usage

Preparing your model

To make your model translatable you need to use the Esign\HelperModelTranslatable\HelperModelTranslatable trait on the model. Next up, you should define which fields are translatable by adding a public $translatable property.

Next up, you may create a helper model just like you're used to:

Retrieving translations

To retrieve a translation in the current locale you may use the attribute you have defined in the translatable property. Or you could use the getTranslation method:

To retrieve a translation in a specific locale you may use the fully suffixed attribute or pass the locale to the getTranslation method:

To check if a translated attribute exists, you may use the hasTranslation method:

In case you need to check if the actual translation model exists, you may use the hasTranslationModel method:

To retrieve the actual translation model you may use the getTranslationModel method:

In case you do not supply a locale, the current locale will be used.

Using a fallback

This package allows you to return the value of an attribute's fallback_locale defined in the config/app.php of your application.

The third useFallbackLocale parameter of the getTranslation method may be used to control this behaviour:

Or you may use dedicated methods for this:

You may configure the fallback locale by overwriting the getFallbackLocale method from the HelperModelTranslatable trait. The locale that was requested initially is passed as a parameter:

Customizing the relationship

By convention, this package assumes your helper model follows the same name of your main model suffixed by Translation, e.g. Post and PostTranslation. This model is used to load the translations relationship that you may customize by either defining the model / foreign key or by overwriting the relationship alltogether.

In case you need to customize the default relationship name you may do so by overwriting the helperModelRelation property on your model:

It's also possible to use a different relationship dynamically by using the useHelperModelRelation method:

Scopes

This package also ships with a few scopes that allow you to set constraints for the translations relationship:

Testing

License

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


All versions of laravel-helpermodel-translatable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/database Version ^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^7.0|^8.0|^9.0|^10.0|^11.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 esign/laravel-helpermodel-translatable contains the following files

Loading the files please wait ....