Download the PHP package davesweb/laravel-translatable without Composer

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

Add translation to Laravel Models by adding a translation model and a translation database table.

Installation

Via composer

Configuration

As long as the names of the translation model and the foreign key column follow the naming conventions, the package will automatically find the correct models and set the correct relations.

The name of the translation model should be the same as the model that is being translated with the suffix Translation, for example App\Page and App\PageTranslation.

The name of the foreign key column should be the name of the model that is being translated in snake case, suffixed with the name of the primary key. For instance page_id. If your model names differ from te naming convention you can specify them yourself on the models. For the model to be translated, add a $translation property.

For translation models you can set the translates property.

Docker

This package has a Docker setup for easy development. To use it, simply copy the docker-compose.yaml.dist file to docker-compose.yaml and adjust anything you'd want to adjust.

Then up the container:

Now you can log in to the container:

Usage

Because the translations are just a one-to-many relation of the model you can use them the same way as any other one-to-many relationship in Laravel. There are a few helper methods to make it easier to use the package, but the base is just a relation.

Fetching translations

You can get the collection of all translations from a model by calling getTranslations().

In order to optimize your database calls you should eager-load your translations:

Or load only the translation in the locale you want:

You can fetch a single translation by calling getTranslation('locale').

To get the translation in the current locale the app is in you can call translation().

To get the value of a translated attribute in the current locale the app is in you can call translate('attribute').

To get the value of a translated attribute in a different locale then the current app locale is in you can call translate('attribute', 'locale') with the desired locale.

Saving translations

Saving a translation is done just like any other Laravel Model. Set the attributes on the TranslationModel in your preferred way, then save it to the model by calling $page->translations()->save($pageTranslation);

Artisan commands

There are three command available for this package:

This command creates a new Model class with the given {name} and the HasTranslations trait already set. This command has a few options as well:

This command creates a new TranslationModel class with the given {name}.

This command creates a new migration with both the model and translation model migrations for the given {name}. The {name} should be the classname of the model, for instance App\Page.

Testing

To run the testsuite, simply run

Code style

This package uses PHP CS Fixer to enforce code style. To run it, run

License

This package is licensed under the MIT license, which basically means you can do whatever your want with this package. However, if you found this package useful, please consider buying me a beer or subscribing to premium email support over on Patreon, it's really appreciated!


All versions of laravel-translatable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^8.0
illuminate/console Version ^8.0
illuminate/database Version ^8.0
illuminate/filesystem Version ^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 davesweb/laravel-translatable contains the following files

Loading the files please wait ....