mercredi 7 mars 2018

laravel 5.1 required_without validation

Using laravel 5.4 I have 2 fields: kg_bags and g_bags

At least one of them has to have a positive value bigger than Zero.

How do I change the validation required_without to do that?

If I put Zero or -value in one and nothing in the other, I don't get an error, which is wrong.

My code:

 if($request->kg_bags) {
        $this->validate($request,[
            "kg_bags" => "numeric"
        ]);
    }

    if($request->g_bags)
    {
        $this->validate($request,[
            "g_bags" => "numeric"
        ]);
    }

    $this->validate($request,[
        "kg_bags" => "required_without:g_bags",
        "g_bags" => "required_without:kg_bags"
    ],
    [
        'kg_bags.required_without' => 'Please fill in the number of bags you packed',
        'g_bags.required_without' => 'Please fill in the number of bags you packed',
    ]);



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2oUgfCf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire