$array1 * @param array $array2 * @return array */ public static function arrayMergeRecursiveDistinct(array &$array1, array &$array2): array { $merged = $array1; foreach ($array2 as $key => &$value) { if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { $merged[$key] = self::arrayMergeRecursiveDistinct($merged[$key], $value); } else { $merged[$key] = $value; } } return $merged; } /** * Asserts that the field is unique. * * @param array|string|int|float|bool|null $value * * @throws \Illuminate\Validation\ValidationException If the field is not unique. */ public static function assertFieldIsUnique( string $table, string $field, string | int | float | bool | null | array $value, null | int | string $id = null, \Closure | string | null $query = null ): void { if (! $query) { Validator::make([$field => $value], [ (string) str_replace('.', '\.', $field) => Rule::unique($table, $field)->ignore($id), ], [ (string) str_replace('.', '\.', "{$field}.unique") => trans( 'crud.libs.toolbox.assertFieldIsUnique', ['attribute' => $field, 'value' => is_array($value) ? json_encode($value) : $value] ), ])->validate(); return; } Validator::make([$field => $value], [ $field => Rule::unique($table)->where($query)->ignore($id), ], [ $field . '.unique' => trans( 'crud.libs.toolbox.assertFieldIsUnique', ['attribute' => $field, 'value' => is_array($value) ? json_encode($value) : $value] ), ])->validate(); } /** * Get original polyfill with autotranslate behavior */ public static function getOriginal(Model $model, string $attribute): mixed { // @phpstan-ignore method.notFound (\Spatie\Translatable\HasTranslations could be absent) if (\in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model)) && $model->isTranslatableAttribute($attribute)) { // @phpstan-ignore method.notFound (\Spatie\Translatable\HasTranslations could be absent) return $model->getTranslation( $attribute, // @phpstan-ignore method.notFound (\Spatie\Translatable\HasTranslations could be absent) $model->getLocale(), // @phpstan-ignore method.notFound (\Spatie\Translatable\HasTranslations could be absent) $model->useFallbackLocale() ); } return $model->getOriginal($attribute); } }