Download the PHP package guidocella/laravel-multilingual without Composer

On this page you can find all versions of the php package guidocella/laravel-multilingual. 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-multilingual

Laravel Multilingual Models

Make Eloquent model attributes translatable without separate database tables for translation values.

Simply access $country->name and you get a value based on your application's current locale.

$country->nameTranslations->en will be the value of a specific locale.

You can get all the translations of a given attributes with $country->nameTranslations->toArray().

Installation

Install the package through Composer:

Then publish the config file:

Usage

First make sure that the translatable attributes' field type is text or json. If you are building the database from a migration file you may do this:

Now that you have the database ready to save a JSON string, add the Translatable trait to your models and a public array property $translatable that holds the names of the translatable fields.

The trait will override the getCasts method to instruct Eloquent to cast all $translatable attributes to array without having to specify them again in $casts.

Now that our model's name attribute is translatable, when creating a new model you may specify the name field as follows:

It will be automatically converted to a JSON string and saved in the name field of the database. You can later retrieve the name like this:

This will return the country name based on the current locale. If the translation in the current locale doesn't have a non-null value then the fallback_locale defined in the config file will be used.

In case nothing can be found null will be returned.

You may also want to return the value for a specific locale; you can do it using the following syntax:

This will return the English name of the country.

To return an array of all the available translations you may use:

You can update the translation in a single locale with Eloquent's arrow syntax for JSON fields:

Validation

You can validate the presence of specific locales like so:

However, this package includes the translatable_required validation rule for requiring that the translations are provided in every locale:

You may define the available locales as well as the fallback_locale from the package config file.

Now you only need to add the translated message of our new validation rule: add this to the validation.php translation file:

Queries

Laravel lets you query JSON columns with the -> operator:


All versions of laravel-multilingual with dependencies

PHP Build Version
Package Version
Requires illuminate/database Version ^12
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 guidocella/laravel-multilingual contains the following files

Loading the files please wait ....