Check out sometimes() method. I'm not sure if it's available for 5.3 though.
Dec 10, 2018
6
Level 8
require_if other field contains some value
Hello,
I'm using Request to validate input, I want to make field required whether another field contains some value or not Im doing like this
'services' => 'required|array',
'packet' => 'required_if:services.*,in:internet_packet',
I want to make packet field required if services array contains 'internet_packet', but this does not work, I use Laravel 5.3. Any suggestions?
Thanks in Advance
Level 8
Thanks a lot to you guys, the solution I did was as follows:
public function rules(){
$rules = [
...
'services' => 'required|array',
...
];
foreach($this->services as $service){
if($service === 'internet_packet')){
$rules['packet'] = 'required|integer';
}
if($service === 'another_value'){
$rules['other_value'] = 'required|.....';
}
...
}
return $rules;
}
Please or to participate in this conversation.