Not recognized more than one rule

This is my code:
Select::make('frequency')
->options([
'weekly' => 'Semanalmente',
'fortnightly' => 'Quincenal',
'monthly_twice' => 'Dos veces al mes',
'monthly' => 'Mensual',
'quarterly' => 'Trimestral',
'annually' => 'Anualmente',
])->required(),
TextInput::make('frequency_day_1')->numeric()->rules([function (Closure $get) {
$frequency = $get('frequency');
\Log::alert($frequency);
switch ($frequency)
{
case 'weekly':
return 'max:7|min:1';
break;
case 'fortnightly':
return 'max:7';
break;
default:
return;
break;
}
}]),
Select::make('frequency')
->options([
'weekly' => 'Semanalmente',
'fortnightly' => 'Quincenal',
'monthly_twice' => 'Dos veces al mes',
'monthly' => 'Mensual',
'quarterly' => 'Trimestral',
'annually' => 'Anualmente',
])->required(),
TextInput::make('frequency_day_1')->numeric()->rules([function (Closure $get) {
$frequency = $get('frequency');
\Log::alert($frequency);
switch ($frequency)
{
case 'weekly':
return 'max:7|min:1';
break;
case 'fortnightly':
return 'max:7';
break;
default:
return;
break;
}
}]),
what I'm trying to do is create different rules depending on what the user chooses in the select. It only works for me if I use one rule, when I use more than one it returns this error: "The given value "7|min:1" does not represent a valid number."
5 Replies
Dennis Koch
Dennis Koch2y ago
Try returning them as an array
Ander
AnderOP2y ago
i try this
case 'weekly':
return ['max:7','min:1'];
break;
case 'weekly':
return ['max:7','min:1'];
break;
but returns this error: Method Illuminate\Validation\Validator::validateMax:7 does not exist.
awcodes
awcodes2y ago
take the array brackets off that are surrounding your function. ->rules(function() {})
LeandroFerreira
Select::make('frequency')
->options([
'weekly' => 'Semanalmente',
'fortnightly' => 'Quincenal',
'monthly_twice' => 'Dos veces al mes',
'monthly' => 'Mensual',
'quarterly' => 'Trimestral',
'annually' => 'Anualmente'
])
->reactive(),

TextInput::make('frequency_day_1')
->numeric()
->minValue(fn ($get): ?int => $get('frequency') === 'weekly' ? 1 : null)
->maxValue(fn ($get): ?int => $get('frequency') === 'weekly' || $get('frequency') === 'fortnightly' ? 7 : null)
Select::make('frequency')
->options([
'weekly' => 'Semanalmente',
'fortnightly' => 'Quincenal',
'monthly_twice' => 'Dos veces al mes',
'monthly' => 'Mensual',
'quarterly' => 'Trimestral',
'annually' => 'Anualmente'
])
->reactive(),

TextInput::make('frequency_day_1')
->numeric()
->minValue(fn ($get): ?int => $get('frequency') === 'weekly' ? 1 : null)
->maxValue(fn ($get): ?int => $get('frequency') === 'weekly' || $get('frequency') === 'fortnightly' ? 7 : null)
?
Ander
AnderOP2y ago
Thanks to all!!
Want results from more Discord servers?
Add your server