Friday, April 14, 2017

Laravel validation required_without_all

Call me stupid, but I can't get it :) I want to set up validator rule, so it will pass only if one of the two fields is present (adgroup or all_adgroups).

Here is my controller:

 $this->validate($request,
        [
            'new_target_cpa_value' => 'required|numeric',
            'adgroups' => 'exists:google.ad_groups,id|required_without_all:all_agroups',
            'all_agroups' => 'required_without_all:adgroups'
        ]
    );
    dd($request->all());

Here is dd:

"_token" => "aHjluUXPuZpEbglmVt4UePhriGvRWDOjk3OgfF88" "new_target_cpa_value" => "123" "adgroups" => array:1 [▶] "all_agroups" => "1"



via Branko Dragovic

Advertisement