Senario:
- Title under each category will be unique.
- I want to write a custom validator which cheks if same title with category exists.
Problem:
If I add one title it validates the uniqeness under same category. Such:

But if I add multiple rows, validation does not work. Such:

I think foreach in 'CategoryResolverTitle' file is being exicuted once. What is the solution. My Form
<label for="Title">Title</label>
<input type="text" name="names[]" class="form-control">
My Custom Validator:
<?php
namespace App\Rules;
use App\Models\QueryManagement\CategoryResolver;
use Illuminate\Contracts\Validation\Rule;
class CategoryTitle implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
foreach ($value as $element) {
return !Category::whereDepartmentId(request('department'))->whereName($element)->exists();
}
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Title under same category must be unique';
}
}