How to validate multiple records insertion in laravel?
<p>My app has a form where I insert multiple records, each record is a new form. I want to validate each field in each form I tried to use validate function but I am confused how to do it for multiple records insert ? For this project I am using laravel 5.2.</p>

<p>Store Function For Multiple Insert</p>

<pre><code>public function store(Request $request)
    {
        $this-&gt;validate($request,[
            'name' =&gt; 'required|min:4',
            'fname' =&gt; 'required',
            'rollno' =&gt; 'required|unique:students'
        ]);
        $input = $request-&gt;all();
        $condition = $input['name'];
        foreach ($condition as $key =&gt; $condition) {
            $student = new Student;
            $student-&gt;name = $input['name'][$key];
            $student-&gt;fname = $input['fname'][$key];
            $student-&gt;rollno = $input['rollno'][$key];
            $student-&gt;obtainedmarks = $input['obtainedmarks'][$key];
            $student-&gt;totalmarks = $input['totalmarks'][$key];
            $student-&gt;percentage = $input['percentage'][$key];
            $student-&gt;save();
        }
        return Redirect::to('/allresults');

}
</code></pre>

<p>View For Inserting data</p>

<pre><code>@extends('layouts.app')
@section('content')
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
    $(function () {
        $('.add').click(function () {
            var n = ($('.resultbody tr').length - 0) + 1;
            var tr = '&lt;tr&gt;&lt;td class="no"&gt;' + n + '&lt;/td&gt;' +
                    '&lt;td&gt;&lt;input type="text" class="name form-control" name="name[]" value="{{ old('name') }}"&gt;&lt;/td&gt;'+
                    '&lt;td&gt;&lt;input type="text" class="fname form-control" name="fname[]" value="{{ old('fname') }}"&gt;&lt;/td&gt;'+
                    '&lt;td&gt;&lt;input type="text" class="rollno form-control" name="rollno[]" value="{{ old('rollno') }}"&gt;&lt;/td&gt;'+
                    '&lt;td&gt;&lt;input type="text" class="obtainedmarks form-control" name="obtainedmarks[]" value="{{ old('email') }}"&gt;&lt;/td&gt;'+
                    '&lt;td&gt;&lt;input type="text" class="totalmarks form-control" name="totalmarks[]"&gt;&lt;/td&gt;'+
                    '&lt;td&gt;&lt;input type="text" class="percentage form-control" name="percentage[]"&gt;&lt;/td&gt;'+
                    '&lt;td&gt;&lt;input type="button" class="btn btn-danger delete" value="x"&gt;&lt;/td&gt;&lt;/tr&gt;';
            $('.resultbody').append(tr);
        });

        $('.resultbody').delegate('.delete', 'click', function () {
            $(this).parent().parent().remove();
        });

        $('.resultbody').delegate('.obtainedmarks , .totalmarks', 'keyup', function () {
            var tr = $(this).parent().parent();
            var obtainedmarks = tr.find('.obtainedmarks').val() - 0;
            var totalmarks = tr.find('.totalmarks').val() - 0;

            var percentage = (obtainedmarks / totalmarks) * 100;
            tr.find('.percentage').val(percentage);
        });
    });
&lt;/script&gt;

&lt;div class="container"&gt;
    &lt;div class="row"&gt;
        &lt;div class="col-md-10 col-md-offset-1"&gt;
            &lt;div class="panel panel-default"&gt;
                &lt;div class="panel-heading"&gt;Add Results&lt;/div&gt;
                @if(count($errors) &gt;0 )
                    &lt;ul&gt;
                        @foreach($errors-&gt;all() as $error)
                            &lt;li&gt;{{$error}}&lt;/li&gt;
                        @endforeach
                    &lt;/ul&gt;
                @endif
                &lt;div class="panel-body"&gt;
                   &lt;form class="form-horizontal" role="form" method="POST" action="{{ url('/result') }}"&gt;
                        {!! csrf_field() !!}
                    &lt;table class="table table-striped"&gt;
                            &lt;thead&gt;
                                &lt;tr&gt;
                                    &lt;th&gt;ID&lt;/th&gt;
                                    &lt;th&gt;Student Name&lt;/th&gt;
                                    &lt;th&gt;Father Name&lt;/th&gt;
                                    &lt;th&gt;Roll No&lt;/th&gt;
                                    &lt;th&gt;Obtained Marks&lt;/th&gt;
                                    &lt;th&gt;Total Marks&lt;/th&gt;
                                    &lt;th&gt;%&lt;/th&gt;
                                    &lt;th&gt;Delete&lt;/th&gt;
                                &lt;/tr&gt;
                            &lt;/thead&gt;
                            &lt;tbody class="resultbody"&gt;
                                &lt;tr&gt;
                                    &lt;td class="no"&gt;1&lt;/td&gt;
                                    &lt;td&gt;
                                        &lt;input type="text" class="name form-control" name="name[]" value="{{ old('name') }}"&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        &lt;input type="text" class="fname form-control" name="fname[]" value="{{ old('fname') }}"&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        &lt;input type="text" class="rollno form-control" name="rollno[]" value="{{ old('rollno') }}"&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        &lt;input type="text" class="obtainedmarks form-control" name="obtainedmarks[]" value="{{ old('email') }}"&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        &lt;input type="text" class="totalmarks form-control" name="totalmarks[]"&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        &lt;input type="text" class="percentage form-control" name="percentage[]"&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        &lt;input type="button" class="btn btn-danger delete" value="x"&gt;
                                    &lt;/td&gt;
                                &lt;/tr&gt;

                            &lt;/tbody&gt;
                        &lt;/table&gt;    
                        &lt;center&gt;&lt;input type="button" class="btn btn-lg btn-primary add" value="Add New Item"&gt;   
                        &lt;input type="submit" class="btn btn-lg btn-default" value="Submit"&gt;&lt;/center&gt;
                        &lt;/form&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;&lt;!-- First Row End --&gt;
&lt;/div&gt; &lt;!-- Container End --&gt;

@endsection
</code></pre>

<p><strong>Update :</strong> In the view you will notice there is a button when the user click on that "add new" it adds new row row I want to validate all the rows, each row contains a record. 
<a href="https://i.stack.imgur.com/p6CZT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p6CZT.png" alt="enter image description here"></a></p>