mercredi 26 décembre 2018

how to validate dynamic field array laravel 5.6 with required_with_all?

i have 3 inputs fields i want validation in such a style that if any field (out of 3)is filled then all three are required if none of them is filled then nothing require please tell me the solution in laravel 5.6.

Note:These 3 inputs fields are array.If someone click on add more button this fields will be increment.

I tried required_with and required_with all but nothing gain.i saw another posts not solved my problem.

My Controller

public function createStore(Request $request)
{   


    $request->validate([

       'holidays_title'   => 'array|min:1|required_with_all:opening_holidays_hours,closing_holidays_hours',
         'opening_holidays_hours' => 'required_with_all:holidays_title,closing_holidays_hours',
         'closing_holidays_hours' => 'required_with_all:holidays_title,opening_holidays_hours',


    ]);

    return redirect()->back();
}

Expected: I just want if any one out of 3 is filled then two others fields must be required.If none of them is filled then no required.

Actual Result: but now no errors are showing me in my view if i filled the title field and submit the form



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire