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

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

Make Eloquent models translatable

Latest Version on Packagist Total Downloads GitHub Actions

This package allows you to make eloquent models translatable by using separate columns for each language, e.g. title_nl and title_en. This package is heavily inspired by Spatie's spatie/laravel-translatable.

Installation

You can install the package via composer:

Usage

Preparing your model

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

Your database structure should look like the following:

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 translation exists, you may use the hasTranslation 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:

Setting translations

To set the translation for the current locale you may use the attribute you have defined in the translatable property. Or you could pass it immediately when creating a model:

You may also use the setTranslation method:

You could also set multiple translations at once using the setTranslations method or immediately passing them along when creating a model:

This package does not persist translations to the database, so don't forget to save your model:

Defining accessors and mutators

You're able to define accessors just like you're used to in Laravel:

The same goes for mutators:

Testing

License

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


All versions of laravel-underscore-translatable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.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-underscore-translatable contains the following files

Loading the files please wait ....