Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Filament/Pages/Settings/GeneralPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Pages\Settings;

use App\Rules\ValidCronExpression;
use App\Settings\GeneralSettings;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\Grid;
Expand Down Expand Up @@ -64,6 +65,7 @@ protected function getFormSchema(): array
Section::make('Speedtest Settings')
->schema([
TextInput::make('speedtest_schedule')
->rules([new ValidCronExpression()])
->helperText('Leave empty to disable the schedule. You can also use the cron expression generator [HERE](https://crontab.cronhub.io/) to help you make schedules.')
->nullable()
->columnSpan(1),
Expand Down
26 changes: 26 additions & 0 deletions app/Rules/ValidCronExpression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Rules;

use Cron\CronExpression;
use Illuminate\Contracts\Validation\InvokableRule;

class ValidCronExpression implements InvokableRule
{
/**
* Validates a string cron expression is correct
*
* @param string $attribute
* @param mixed $value
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function __invoke($attribute, $value, $fail)
{
$is_valid = CronExpression::isValidExpression($value);

if (! $is_valid) {
$fail('Cron expression is not valid');
}
}
}