HEX
Server: LiteSpeed
System: Linux s17244.fra1.stableserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User: jubaroyal (1259)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /home/jubaroyal/public_html/app/Rules/AgeBetween.php
<?php

namespace App\Rules;

use Carbon\Carbon;
use Illuminate\Contracts\Validation\Rule;

class AgeBetween implements Rule
{
    private $minAge;
    private $maxAge;

    /**
     * Create a new rule instance.
     *
     * @param int $minAge
     * @param int $maxAge
     * @return void
     */
    public function __construct(int $minAge, int $maxAge)
    {
        $this->minAge = $minAge;
        $this->maxAge = $maxAge;
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param string $attribute
     * @param mixed $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $today = Carbon::today();
        $dob = Carbon::parse($value);
        $age = $dob->diffInYears($today);

        return $age >= $this->minAge && $age <= $this->maxAge;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute must give age between ' . $this->minAge . ' and ' . $this->maxAge . ' years old.';
    }
}