@@ 9-38 (lines=30) @@ | ||
6 | use Spatie\ValidationRules\IsDateRule; |
|
7 | use Illuminate\Contracts\Validation\Rule; |
|
8 | ||
9 | class FutureDate implements Rule |
|
10 | { |
|
11 | use IsDateRule; |
|
12 | ||
13 | /** @var string|null */ |
|
14 | protected $message = null; |
|
15 | ||
16 | public function __construct(string $format = 'Y-m-d') |
|
17 | { |
|
18 | $this->format = $format; |
|
19 | } |
|
20 | ||
21 | public function passes($attribute, $value): bool |
|
22 | { |
|
23 | try { |
|
24 | $date = $this->createDate($value); |
|
25 | ||
26 | return $date->isFuture(); |
|
27 | } catch (InvalidDate $exception) { |
|
28 | $this->message = $exception->getMessage(); |
|
29 | ||
30 | return false; |
|
31 | } |
|
32 | } |
|
33 | ||
34 | public function message(): string |
|
35 | { |
|
36 | return $this->message ?? __('validationRules.future_date'); |
|
37 | } |
|
38 | } |
|
39 |
@@ 9-38 (lines=30) @@ | ||
6 | use Spatie\ValidationRules\IsDateRule; |
|
7 | use Illuminate\Contracts\Validation\Rule; |
|
8 | ||
9 | class PastDate implements Rule |
|
10 | { |
|
11 | use IsDateRule; |
|
12 | ||
13 | /** @var string|null */ |
|
14 | protected $message; |
|
15 | ||
16 | public function __construct(string $format = 'Y-m-d') |
|
17 | { |
|
18 | $this->format = $format; |
|
19 | } |
|
20 | ||
21 | public function passes($attribute, $value): bool |
|
22 | { |
|
23 | try { |
|
24 | $date = $this->createDate($value); |
|
25 | ||
26 | return $date->isPast(); |
|
27 | } catch (InvalidDate $exception) { |
|
28 | $this->message = $exception->getMessage(); |
|
29 | ||
30 | return false; |
|
31 | } |
|
32 | } |
|
33 | ||
34 | public function message(): string |
|
35 | { |
|
36 | return $this->message ?? __('validationRules.past_date'); |
|
37 | } |
|
38 | } |
|
39 |