Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

559 B
Raw Blame
<?php

namespace HiEvents\Validators\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class InsensitiveIn implements ValidationRule
{
    protected array $values;

    public function __construct(array $values)
    {
        $this->values = array_map('strtoupper', $values);
    }

    public function validate(string $attribute, mixed $value, Closure $fail): void
    {
        if (! in_array(strtoupper($value), $this->values, true)) {
            $fail(':attribute must be one of '.implode(', ', $this->values));
        }
    }
}