vendredi 2 août 2019

Laravel exists validation if the given value is not zero

This is my situation:

Assume I have a radio input in my html form which it's value must to exists in a table only IF user check one of them, else the value have to be zero

this my structure:

<div class="inputGroup">
    <input id="first_change1" name="first_change" type="radio" value=""  />
    <label for="first_change1" class="farsi"></label>
</div>
<div class="inputGroup">
    <input id="first_change2" name="first_change" type="radio" value=""  />
    <label for="first_change2" class="farsi"></label>
</div>
<div class="inputGroup">
    <input id="first_change3" name="first_change" type="radio" value="0"  />
    <label for="first_change3" class="farsi">None of them</label>
</div>
@if( $errors->has('first_change'))
    <h6 class="alert alert-danger farsi text-danger rtl text-right">
         <i class="fa fa-2x fa-arrow-up fleft" style="bottom: 5px !important;"></i>
    </h6>
@endif

And this is my current validation for this field:

'first_change' => 'required|exists:fc_teams,id',

But I need something like this:

'first_change' => 'required|[IF VALUE IS NOT -0-; THEN]exists:fc_teams,id',



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire