mercredi 15 juillet 2020

How to display validation error for same name fields in Laravel?

I want to display each field validation error. But couldn't be able to do.

<form class="default_form my_smtp_form row m-0" method="post"
                      action="">
                    @csrf

                    @if($paymentSettingsInfo)
                        @foreach($paymentSettingsInfo as $singlePaymentSettingsInfo)
                            <div class="col-sm-12 my-2 col-md-4">
                                <div class="form-group">
                                    <label>&nbsp;</label>
                                    <input type="text" onfocus="select();" name="secret_key[]" class="form-control"
                                           placeholder="Secret Key" value="">
                                    @if ($errors->has('secret_key'))
                                        <div class="invalid_feedback"></div>
                                    @endif
                                </div>
                            </div>
                        @endforeach
                    @endif
                    <div class="col-sm-12 p-0">
                        <button type="submit" class="c-btn btn-fill submit-btn">Submit</button>
                    </div>
                </form>

I know that following code works for one and only having unique name input field. But how to do for multiple input fields with the same name?

@if ($errors->has('secret_key'))
    <div class="invalid_feedback"></div>
@endif


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire