Download the PHP package codezero/laravel-unique-translation without Composer

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

Laravel Unique Translation

IMPORTANT: March 2022

Support Ukraine

It's horrible to see what is happening now in Ukraine, as Russian army is bombarding houses, hospitals and kindergartens.

Please check out supportukrainenow.org for the ways how you can help people there. Spread the word.

And if you are from Russia and you are against this war, please express your protest in some way. I know you can get punished for this, but you are one of the hopes of those innocent people.


GitHub release Laravel Build Status Code Coverage Code Quality Total Downloads

ko-fi

Check if a translated value in a JSON column is unique in the database.

Imagine you want store a slug for a Post model in different languages.

The amazing spatie/laravel-translatable package makes this a cinch!

But then you want to make sure each translation is unique for its language.

That's where this package comes in to play.

This package also supports spatie/nova-translatable in case you are using Laravel Nova and filamentphp/spatie-laravel-translatable-plugin in case you are using Filament.

✅ Requirements

📦 Installation

Require the package via Composer:

Laravel will automatically register the ServiceProvider.

🛠 Usage

For the following examples, I will use a slug in a posts table as the subject of our validation.

☑️ Validate a Single Translation

Your form can submit a single slug:

We can then check if it is unique in the current locale:

You could also use the Rule instance:

☑️ Validate an Array of Translations

Your form can also submit an array of slugs.

We need to validate the entire array in this case. Mind the slug.* key.

☑️ Specify a Column

Maybe your form field has a name of post_slug and your database field slug:

☑️ Specify a Database Connection

If you are using multiple database connections, you can specify which one to use by prepending it to the table name, separated by a dot:

☑️ Ignore a Record with ID

If you're updating a record, you may want to ignore the post itself from the unique check.

☑️ Ignore Records with a Specific Column and Value

If your ID column has a different name, or you just want to use another column:

☑️ Use Additional Where Clauses

You can add 4 types of where clauses to the rule.

where

whereNot

whereNull

whereNotNull

☑️ Laravel Nova

If you are using Laravel Nova in combination with spatie/nova-translatable, then you can add the validation rule like this:

☑️ Filament

If you are using Filament in combination with filamentphp/spatie-laravel-translatable-plugin, then you can add the validation rule like this:

🖥 Example

Your existing slug column (JSON) in a posts table:

Your form input to create a new record:

Your validation logic:

The result is that slug[en] is valid, since the only en value in the database is not-abc.

And slug[nl] would fail, because there already is a nl value of abc.

⚠️ Error Messages

You can pass your own error messages as normal.

When validating a single form field:

In your view you can then get the error with $errors->first('slug').

Or when validation an array:

In your view you can then get the error with $errors->first('slug.en') (en being your array key).

🚧 Testing

☕️ Credits

🔓 Security

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

📑 Changelog

A complete list of all notable changes to this package can be found on the releases page.

📜 License

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


All versions of laravel-unique-translation with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2|^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 codezero/laravel-unique-translation contains the following files

Loading the files please wait ....