How to validate specific reply form of comments in laravel

  eloquent, laravel, laravel-validation, php

I have a page with multiple forms on it but I need to validate a specific submitted form.

In my view I have this for each input of the forms

<div class="form-group">
    <label for="name">{{ __('Name')}}</label>
    <input class="form-control {{ $errors->has('name') ? 'is-invalid' : '' }}" type="text" name="name" id="name" value="{{ old('name', '') }}">
    @if($errors->storecomment->any())
    <div class="invalid-feedback">
    @foreach($errors->storecomment->all() as $error)
        <li>{{ $error}}</li>
    @endforeach
    </div>
    @endif
</div>

In the StoreCommentRequest class, I added the $errorBag property to specify the form

class StoreCommentRequest extends FormRequest
{
           
    protected $errorBag ="storecomment";
    
    public function authorize()
    {
        return true;
    }
    
    public function rules()
    {
        return [
            'name' => [
                'string',
                'min:5',
                'max:200',
                'nullable',
                 'required',
            ],
            'website' => [
                'string',
                'min:5',
                'max:50',
                'nullable',
            ],
            'comment' => [
                'required',
            ],
        ];
    }
}

I need to validate a selected comment but it shows validation errors on all the forms:

screenshot

Source: Laravel

Leave a Reply