From ce30ad262e2f9df388eb8ec17d8040059e13dad8 Mon Sep 17 00:00:00 2001 From: Pavel Mironchik Date: Wed, 30 Jun 2021 09:52:33 +0600 Subject: [PATCH] Optimize using the dependent validation rules in import. --- app/Abstracts/Import.php | 72 +++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/app/Abstracts/Import.php b/app/Abstracts/Import.php index 17677a69c..8d709b0db 100644 --- a/app/Abstracts/Import.php +++ b/app/Abstracts/Import.php @@ -107,35 +107,53 @@ abstract class Import implements HasLocalePreference, ShouldQueue, SkipsEmptyRow protected function replaceForBatchRules(array $rules): array { $dependent_rules = [ - 'after', - 'after_or_equal', - 'before', - 'before_or_equal', - 'different', - 'exclude_if', - 'exclude_unless', - 'gt', - 'gte', - 'in_array', - 'lt', - 'lte', - 'prohibited_if', - 'prohibited_unless', - 'required_if', - 'required_unless', - 'required_with', - 'required_with_all', - 'required_without', - 'required_without_all', - 'same', + 'after:', + 'after_or_equal:', + 'before:', + 'before_or_equal:', + 'different:', + 'exclude_if:', + 'exclude_unless:', + 'gt:', + 'gte:', + 'in_array:', + 'lt:', + 'lte:', + 'prohibited_if:', + 'prohibited_unless:', + 'required_if:', + 'required_unless:', + 'required_with:', + 'required_with_all:', + 'required_without:', + 'required_without_all:', + 'same:', ]; - foreach ($rules as $field => $rule) { - foreach ($dependent_rules as $dependent_rule) { - $rules[$field] = Str::replaceFirst($dependent_rule . ':', $dependent_rule . ':*.', $rules[$field]); - } - } + $batch_rules = [ + 'after:*.', + 'after_or_equal:*.', + 'before:*.', + 'before_or_equal:*.', + 'different:*.', + 'exclude_if:*.', + 'exclude_unless:*.', + 'gt:*.', + 'gte:*.', + 'in_array:*.', + 'lt:*.', + 'lte:*.', + 'prohibited_if:*.', + 'prohibited_unless:*.', + 'required_if:*.', + 'required_unless:*.', + 'required_with:*.', + 'required_with_all:*.', + 'required_without:*.', + 'required_without_all:*.', + 'same:*.', + ]; - return $rules; + return str_replace($dependent_rules, $batch_rules, $rules); } }