Replies: 4 comments 2 replies
-
I like this idea! |
Beta Was this translation helpful? Give feedback.
-
There is already 'distinct'. Which could be adapted. I hate long underscored names. |
Beta Was this translation helpful? Give feedback.
-
$this->collect('products')
->map(fn (array $product) => Arr::only($product, ['type', 'name']))
->duplicates()->isEmpty() |
Beta Was this translation helpful? Give feedback.
-
array:4 [ We make custom validation rule " distinct_multiple_fields " for check duplicate value in array. `<?php namespace App\Rules; use Illuminate\Contracts\Validation\Rule; class DistinctMultipleFields implements Rule
} How to use:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to valid the array, like the example:
I hope it can have a rule "Distinct Multiple Fields", and I can use the rule like
'product.*' => 'distinct_multiple_fields:type,name'
.Giving the specified fields, and you can valid the value in fields.
So if "type + name" value is duplicate (like the example "type:ticket, name:train"), the validation result will be fail.
But the example "type:ticket, name:train" and "type:toy, name:train" will pass the validation.
If someone who think it works, and I will try to implement the code, thanks. 🙏
And if you have any naming suggestion, please tell me!
Beta Was this translation helpful? Give feedback.
All reactions