I would like to know if it is possible to validate that an input time is between two time limits, I have done the following based on several sites that I reviewed but I do not get a successful result.
class HourBetween implements Illuminate\Contracts\Validation\Rule
{
private $start;
private $end;
public function __construct($start, $end)
{
$this->start = $start;
$this->end = $end;
}
public function passes($attribute, $value)
{
$hour = intval(Illuminate\Support\Str::before($value,':'));
return $hour >= $this->start && $hour < $this->end;
}
public function message()
{
return "The :attribute should be between {$this->start}:00 and {$this->end}:00";
}
}
and then use it like
'start_time' => [
'required',
new HourBetween(9,18),
]