Giter Club home page Giter Club logo

laravel-unique-translation's People

Contributors

bkintanar avatar ctf0 avatar dvandal avatar ecointest avatar ivanvermeyen avatar jackbaron avatar okipa avatar tahiaji avatar theupriser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-unique-translation's Issues

Error during test Undefined array key "collation"

Hi!
Fantastic package. Works great during browser usage, but I get a really weird error when testing the form I want to validate.
Basics:
I am using Laravel-translatable from Spatie and want to check that the title is unique in a JSON column for a specific locale. My form is really simple:

<label>TítuloES</label><br>
<input class="border" type="text" name="title[es]"><br>
<label>TítuloEN</label><br>
<input class="border" type="text" name="title[en]"><br>

My validation looks like this:

 $attributes = request()->validate([
            'title.*' => 'required|max:255|unique_translation:posts,title',
            'summary.*' => 'required',
            'content.*' => 'required',
            'imagetitle' => [
                'sometimes', 
                'mimes:jpeg,jpg,png'
                ]
        ]);

When I use the web, it works, but when I test it, I get a super long error, but the most important part seems this one:

The following exception occurred during the last request:

ErrorException: Undefined array key "collation" in E:\Programas\laragon\www\webtronica\vendor\codezero\laravel-unique-translation\src\UniqueTranslationValidator.php:238
Stack trace:
#0 E:\Programas\laragon\www\myapp\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(259): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Undefined array...', 'E:\\Programas\\la...', 238)
#1 E:\Programas\laragon\www\myapp\vendor\codezero\laravel-unique-translation\src\UniqueTranslationValidator.php(238): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}(2, 'Undefined array...', 'E:\\Programas\\la...', 238)
#2 E:\Programas\laragon\www\myapp\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1551): CodeZero\UniqueTranslation\UniqueTranslationValidator->CodeZero\UniqueTranslation\{closure}(Object(Illuminate\Database\Query\Builder))

I guess the package is trying to get some info from the DB, but it is not getting it. Then, everything breaks. So, I have 2 questions:
Should I somehow modify configuration of PHP unit? Now it looks like this:

  <php>
    <server name="APP_ENV" value="testing"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="DB_CONNECTION" value="sqlite"/>
    <server name="DB_DATABASE" value=":memory:"/>
    <server name="MAIL_DRIVER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
    <env name="DB_CONNECTION" value="sqlite"/>
    <env name="RECAPTCHA_KEY" value="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"/>
    <env name="RECAPTCHA_SECRET" value="6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"/>
  </php>
</phpunit>

Question number 2: when using browser and submitting the form, no error is seen and the post is created with success.
The collation fields of my database are empty, so I don't understand how its working:
imagen

Many thanks!!!

Filament support

Hello,
I tried to use this great package with Filament which handles translations using spatie/nova-translatable in a simple way like Laravel Nova, unfortunately this is not working (allowing duplication).

Laravel Nova

Text::make(__('Slug'), 'slug')
  ->creationRules('unique_translation:posts,slug')
  ->updateRules('unique_translation:posts,slug,{{resourceId}}');

Filament (assumed and tested)

Forms\Components\TextInput::make('slug')->required()
  ->rules(['unique_translation:posts,slug']),
  1. Is there any planned release to support Filament?
  2. Awaiting for an official support, what would be the cleanest way to use it with Filament?

Thanks.

Ignore deleted_at soft deteled field

How can I ignore soft deleted records?

'FIELD_NAME.*' => [
UniqueTranslationRule::for('TABLE_NAME', 'FIELD_NAME')->ignore(!0, 'deleted_at') -> NO WORKS
UniqueTranslationRule::for('TABLE_NAME', 'FIELD_NAME')->ignore(!NULL, 'deleted_at') -> NO WORKS
UniqueTranslationRule::for('TABLE_NAME', 'FIELD_NAME')->whereNull('deleted_at') -> NO WORKS
]

Does not work for PostgreSQL v15

.env
image

database config
image

validation rule
image

result
image

In the end, I settled on using version 3.5.0. It would be nice to have this fixed for 4 ver.

unique validation error while updating using form request

I form for saving the category. The name field is unique. I'm using FormRequest for validating the form. Create works fine. but while updating getting error showing The name.en has already been taken.

form fields

                <input class="form-control" name="name[en]" type="text" id="name-en" value="{{ old('name[en]', optional($serviceCategory)->getTranslation('name','en')) }}" minlength="1" maxlength="255" placeholder="{{ __('preferencesCategory.name_en__placeholder') }}">
                <input class="form-control" name="name[ar]" type="text" id="name-ar" value="{{ old('name[ar]', optional($serviceCategory)->getTranslation('name','ar')) }}" minlength="1" maxlength="255" placeholder="{{ __('preferencesCategory.name_ar__placeholder') }}">

FormRequest.php

  public function rules()
    {
        return [
            'code' => 'string|min:1|nullable',
            'name.*' => 'required|string|min:1|max:255|unique_translation:service_categories,name,{$this->serviceCategory->id}',
            'status' => 'string|min:1|nullable',
        ];

web.php (route file)

Route::put('service_category/{serviceCategory}', 'ServiceCategoriesController@update')
            ->name('service_categories.service_category.update')->where('id', '[0-9]+');

controller.php

public function update(ServiceCategory $serviceCategory, ServiceCategoriesFormRequest $request)
    {
        try {
            $data = $request->getData();
            $data['updated_by'] = \Auth::guard('admin')->user()->id;

            $serviceCategory->update($data);

            return redirect()->route('service_categories.service_category.index')
                ->with('success_message', 'Service Category was successfully updated.');
        } catch (Exception $exception) {
            return back()->withInput()
                ->withErrors(['unexpected_error' => 'Unexpected error occurred while trying to process your request.']);
        }
    }

regarding the error msg

atm to get the error you will use name.code but is there a way to pass an option that make the error msg unified whether am using a code or not ?

ex.

// form
<input name="slug[en]" value="abc">
<input name="slug[nl]" value="abc">

// validate
$attributes = request()->validate([
    'slug.*' => ["unique_translation:posts,slug,{$post->id}"],
]);

// error
@if($errors->has('slug'))
    {{ $errors->first('slug') }}
@endif

this way , either i use a single input or array, the error condition doesnt change.

atm, here is how i do the validation

foreach ($locales as $code) {
    $v = Validator::make($request->all(), ["slug.$code" => "unique:pages,slug->$code," . $id ?: '']);

    if ($v->fails()) {
        $validator->errors()->add('slug', 'this slug is already taken');
    }
}

on a side note

also is it possible to use the validation rule with | pipe rules or do i have to use the array instead ?

How to validate a single value?

In this case:

{
  "en":"unique_title", //scoped for en
  "lt":"unique_title", //scoped for lt
}
<input name="title_en" value="unique_title" />
<input name="title_lt" value="some other title"/>

I want to have different validation for each input like:

$attributes = request()->validate([
    'title_lt' => 'required|unique_translation:posts:title',
    'title_en' => 'unique_translation:posts:title',
]);

how would i check against a specific value? Or this will just work?

Unique validation with ar.

Why unique validation does not work with Arabic language, but with English it's OK!

My code in store method:

Screen Shot 2020-06-30 at 4 41 26 PM

the database:
Screen Shot 2020-06-30 at 4 38 30 PM

Too many messages

Hi
Thanks for your extension.

I have some trouble.

Example

<input type="text" name="post_name[de]">
<input type="text" name="post_name[en]">
class MyRequest extends FormRequest{
  public function rules(): array
    {
        return [
            'post_name.*' => [
                UniqueTranslationRule::for('posts', 'name')
            ]
        ];
}}

When i put exists values and submit form, i got a lot of messages:
screenshot

Is there any way to generate only one message for each language?

Best regards

Unique comparison is case sensitive

It seems that the where clause in the unique_translation rule is case sensitive.

protected function findTranslation($connection, $table, $column, $locale, $value)
{
return DB::connection($connection)->table($table)->where("{$column}->{$locale}", '=', $value);
}

According to my Google searches, MySQL is supposed to be case insensitive when using a collation that ends in _ci (I'm using utf8mb4_unicode_ci). But that's not what my tests are saying...

Is anyone else having this issue?

MariaDB / PostgreSQL compatibility

Hello,
I'm using this package with MariaDB 10.6.9, Laravel 9, PHP 8.1 and Spatie Laravel Translatable v6, but it is not working.
Is it compatible with this environment or only compatible only with MySQL?
Thanks.

an issue with spatie/laravel-tags

am not sure if its an issue with the https://github.com/spatie/laravel-tags package or something is missing from the validation package,

but here is what i have

$request->validate([
    'name.*' => 'unique_translation:tags,name,' . $id
]);

the db name column i will update is

{"en": "black"}

and will be replaced with

{
  "en": "test",
  "fr": null
}

but i keep getting the error that the item already exists in the db, so maybe u can help me with this one

ErrorException: Array to string conversion

Hi, I have an issue using the validation rule provided by the library.

I'm using

  • PHP 8.2
  • Laravel 10
  • Spatie/Laravel-translatable - 6.5
  • codezero/laravel-unique-translation - 4.2

I'm developing a multilingual API application and when I use the validation rule in a Request validator file I get an ErrorException with this data:

{
	"message": "Array to string conversion",
	"exception": "ErrorException",
	"file": "/var/www/html/vendor/codezero/laravel-unique-translation/src/UniqueTranslationValidator.php",
	"line": 273,
	"trace": [
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php",
			"line": 255,
			"function": "handleError",
			"class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/codezero/laravel-unique-translation/src/UniqueTranslationValidator.php",
			"line": 273,
			"function": "Illuminate\\Foundation\\Bootstrap\\{closure}",
			"class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php",
			"line": 1621,
			"function": "CodeZero\\UniqueTranslation\\{closure}",
			"class": "CodeZero\\UniqueTranslation\\UniqueTranslationValidator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php",
			"line": 783,
			"function": "whereNested",
			"class": "Illuminate\\Database\\Query\\Builder",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/codezero/laravel-unique-translation/src/UniqueTranslationValidator.php",
			"line": 271,
			"function": "where",
			"class": "Illuminate\\Database\\Query\\Builder",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/codezero/laravel-unique-translation/src/UniqueTranslationValidator.php",
			"line": 240,
			"function": "findTranslation",
			"class": "CodeZero\\UniqueTranslation\\UniqueTranslationValidator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/codezero/laravel-unique-translation/src/UniqueTranslationValidator.php",
			"line": 32,
			"function": "isUnique",
			"class": "CodeZero\\UniqueTranslation\\UniqueTranslationValidator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Validation/Validator.php",
			"line": 1611,
			"function": "validate",
			"class": "CodeZero\\UniqueTranslation\\UniqueTranslationValidator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Validation/Validator.php",
			"line": 1596,
			"function": "callClassBasedExtension",
			"class": "Illuminate\\Validation\\Validator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Validation/Validator.php",
			"line": 1628,
			"function": "callExtension",
			"class": "Illuminate\\Validation\\Validator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Validation/Validator.php",
			"line": 657,
			"function": "__call",
			"class": "Illuminate\\Validation\\Validator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Validation/Validator.php",
			"line": 457,
			"function": "validateAttribute",
			"class": "Illuminate\\Validation\\Validator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Validation/Validator.php",
			"line": 492,
			"function": "passes",
			"class": "Illuminate\\Validation\\Validator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Validation/ValidatesWhenResolvedTrait.php",
			"line": 31,
			"function": "fails",
			"class": "Illuminate\\Validation\\Validator",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php",
			"line": 30,
			"function": "validateResolved",
			"class": "Illuminate\\Foundation\\Http\\FormRequest",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php",
			"line": 1302,
			"function": "Illuminate\\Foundation\\Providers\\{closure}",
			"class": "Illuminate\\Foundation\\Providers\\FormRequestServiceProvider",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php",
			"line": 1266,
			"function": "fireCallbackArray",
			"class": "Illuminate\\Container\\Container",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php",
			"line": 1252,
			"function": "fireAfterResolvingCallbacks",
			"class": "Illuminate\\Container\\Container",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php",
			"line": 813,
			"function": "fireResolvingCallbacks",
			"class": "Illuminate\\Container\\Container",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php",
			"line": 957,
			"function": "resolve",
			"class": "Illuminate\\Container\\Container",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php",
			"line": 731,
			"function": "resolve",
			"class": "Illuminate\\Foundation\\Application",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php",
			"line": 942,
			"function": "make",
			"class": "Illuminate\\Container\\Container",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ResolvesRouteDependencies.php",
			"line": 85,
			"function": "make",
			"class": "Illuminate\\Foundation\\Application",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ResolvesRouteDependencies.php",
			"line": 50,
			"function": "transformDependency",
			"class": "Illuminate\\Routing\\ControllerDispatcher",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ResolvesRouteDependencies.php",
			"line": 29,
			"function": "resolveMethodDependencies",
			"class": "Illuminate\\Routing\\ControllerDispatcher",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
			"line": 59,
			"function": "resolveClassMethodDependencies",
			"class": "Illuminate\\Routing\\ControllerDispatcher",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
			"line": 40,
			"function": "resolveParameters",
			"class": "Illuminate\\Routing\\ControllerDispatcher",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
			"line": 259,
			"function": "dispatch",
			"class": "Illuminate\\Routing\\ControllerDispatcher",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
			"line": 205,
			"function": "runController",
			"class": "Illuminate\\Routing\\Route",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
			"line": 806,
			"function": "run",
			"class": "Illuminate\\Routing\\Route",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 144,
			"function": "Illuminate\\Routing\\{closure}",
			"class": "Illuminate\\Routing\\Router",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/rakutentech/laravel-request-docs/src/LaravelRequestDocsMiddleware.php",
			"line": 49,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Rakutentech\\LaravelRequestDocs\\LaravelRequestDocsMiddleware",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
			"line": 50,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
			"line": 159,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
			"line": 125,
			"function": "handleRequest",
			"class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
			"line": 87,
			"function": "handleRequestUsingNamedLimiter",
			"class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php",
			"line": 57,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Illuminate\\Auth\\Middleware\\Authenticate",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/sanctum/src/Http/Middleware/EnsureFrontendRequestsAreStateful.php",
			"line": 25,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 144,
			"function": "Laravel\\Sanctum\\Http\\Middleware\\{closure}",
			"class": "Laravel\\Sanctum\\Http\\Middleware\\EnsureFrontendRequestsAreStateful",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 119,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/sanctum/src/Http/Middleware/EnsureFrontendRequestsAreStateful.php",
			"line": 24,
			"function": "then",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Laravel\\Sanctum\\Http\\Middleware\\EnsureFrontendRequestsAreStateful",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 119,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
			"line": 805,
			"function": "then",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
			"line": 784,
			"function": "runRouteWithinStack",
			"class": "Illuminate\\Routing\\Router",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
			"line": 748,
			"function": "runRoute",
			"class": "Illuminate\\Routing\\Router",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
			"line": 737,
			"function": "dispatchToRoute",
			"class": "Illuminate\\Routing\\Router",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
			"line": 200,
			"function": "dispatch",
			"class": "Illuminate\\Routing\\Router",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 144,
			"function": "Illuminate\\Foundation\\Http\\{closure}",
			"class": "Illuminate\\Foundation\\Http\\Kernel",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php",
			"line": 66,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Barryvdh\\Debugbar\\Middleware\\InjectDebugbar",
			"type": "->"
		},
		{
			"file": "/var/www/html/app/Http/Middleware/LocalizationMiddleware.php",
			"line": 44,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "App\\Http\\Middleware\\LocalizationMiddleware",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php",
			"line": 121,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php",
			"line": 64,
			"function": "handleStatefulRequest",
			"class": "Illuminate\\Session\\Middleware\\StartSession",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Illuminate\\Session\\Middleware\\StartSession",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
			"line": 21,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php",
			"line": 31,
			"function": "handle",
			"class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
			"line": 21,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php",
			"line": 40,
			"function": "handle",
			"class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Illuminate\\Foundation\\Http\\Middleware\\TrimStrings",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
			"line": 27,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php",
			"line": 99,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php",
			"line": 62,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 183,
			"function": "handle",
			"class": "Illuminate\\Http\\Middleware\\HandleCors",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
			"line": 119,
			"function": "Illuminate\\Pipeline\\{closure}",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
			"line": 175,
			"function": "then",
			"class": "Illuminate\\Pipeline\\Pipeline",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
			"line": 144,
			"function": "sendRequestThroughRouter",
			"class": "Illuminate\\Foundation\\Http\\Kernel",
			"type": "->"
		},
		{
			"file": "/var/www/html/public/index.php",
			"line": 51,
			"function": "handle",
			"class": "Illuminate\\Foundation\\Http\\Kernel",
			"type": "->"
		},
		{
			"file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php",
			"line": 16,
			"function": "require_once"
		}
	]
}

The Request validator file:

public function rules(): array
    {
        return [
            'name' => [
                'required',
                UniqueTranslationRule::for('ticket_statuses', 'name'),
            ],
            'description' => 'nullable|array',
            'color' => [
                'string',
                new Enum(Colors::class),
            ],
            'sort_order' => 'required|integer|between:0,255',
        ];
    }

The provided data as JSON:

{
	"name": {
		"bg": "asd",
		"en": "asd"
	},
	"description": {
		"bg": "asd",
		"en": "asd"
	},
	"color": "slate",
	"sort_order": 0
}

I went into the library code and used a dd() statement on line 272 of the UniqueTranslationValidator.php file: dd($column, $operator, $locale, $value);

The dumped data is:

"name" // vendor/codezero/laravel-unique-translation/src/UniqueTranslationValidator.php:272
"LIKE" // vendor/codezero/laravel-unique-translation/src/UniqueTranslationValidator.php:272
"bg" // vendor/codezero/laravel-unique-translation/src/UniqueTranslationValidator.php:272
array:2 [▼ // vendor/codezero/laravel-unique-translation/src/UniqueTranslationValidator.php:272
  "bg" => "asd"
  "en" => "asd"
]

I don't understand if I'm doing something wrong or if there is a bug in the lib.

UniqueTranslationRule is ignored - Laravel 8

Hello @ivanvermeyen!

First, thanks for developing this great package. I'm trying to use it on a Laravel 8 project I started recently, but I can't get it to work. I'm pretty sure I forgot something stupid, but I've been looking for a week and even showed it to a colleague, but we can't find an error. Maybe you can help me?

When I try to update a post with the same slug as another (or create once with the same slug as another), the UniqueTranslationRule rule doesn't detect it. My form request App\Http\Requests\Admin\PostRequest has this rules function :

public function rules()
    {
        return [
            'post.title' => 'required|string',
            'post.slug' => ['required', 'max:2000', UniqueTranslationRule::for('posts', 'slug'), 'regex:/^([a-z0-9\-\/]*)$/'],
            'post.category_id' => ['nullable', 'numeric', Rule::exists('categories', 'id')
                ->where('deleted_at', NULL)->where('type', Category::TYPE_POST)],
        ];
    }

Things I checked :

  • Spatie\laravel-translatable is working (all data are saved in JSON in the database)
  • I call use CodeZero\UniqueTranslation\UniqueTranslationRule; at the beginning of the file
  • I remove and resinstalled the package with composer require codezero/laravel-unique-translation

Thanks in advance ! 🙏

getFilamentAttributeNameAndLocale Returns an array incorrectly

 protected function getFilamentAttributeNameAndLocale($attribute)
    {
        $attribute = str_replace('data.', '', $attribute);
	@list($locale, $name) = @explode('.', $attribute);
        return [$name, $locale];
    }

Need to switch places

@list($name, $locale) = @explode('.', $attribute);

Is compatible with Astrotomic/laravel-translatable?

I am using the Astrotomic/Laravel-Translatable package for the translation of my content through the models, but for me to validate with this package it is as follows

"es_name"     => [
    "required_without:en_name,en_slug,en_extract,en_body",
    "required_with:es_slug",
    Rule::unique("blog_post_translations", "name")->where(function ($query) {
        return $query->where("locale", "es");
    }),
],
"es_slug"     => [
    "required_without:en_name,en_slug,en_extract,en_body",
    "required_with:es_name",
    Rule::unique("blog_post_translations", "slug")->where(function ($query) {
        return $query->where("locale", "es");
    }),
],

I see that the use of this package makes this validation much easier

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.