Laravel 5.2 New Table singular group input verification, sounds very ignorant? Let's demonstrate this feature in a concrete example.
The corresponding route is defined first in routes.php:
Route::get (' form ', ' testcontroller@form '); Route::p ost (' Form/validate ', ' testcontroller@validate ');
Then use the artisan command to create the corresponding controller:
PHP Artisan Make:controller TestController
Edit the generated testcontroller.php file with the following contents:
Next create the Form view file resources/views/test/form.blade.php, and edit the contents of the form.blade.php file as follows:
@extends (' Layouts.app ') @section (' content ') @if (count ($errors) > 0)
@foreach ($errors->all ( ) as $error)
- {{$error}}
@endforeach
@endif @endsection
We defined the array input fields Employee[][name] and Employee[][title] in the form to enter multiple employee names and positions at the same time.
Also, notice that we injected the Formrequest request class into the Validate method of the controller TestController, we will implement the form input validation logic in this class, and we use the Artisan command to generate this request class:
PHP Artisan make:request formrequest
This generates formrequest.php in the App/http/requests directory, and the contents of the file are edited as follows:
' required|max:100 ', ' employee.*.name ' = ' required|max:100 ', ' employee.*.title ' = ' Required|max ' : [ ]; }}
At this point, we have completed the code writing work, we will test the array input validation, in the browser to access Http://laravel.app/form, the page is displayed as follows:
We then enter some form data:
Finally, click on the "Submit" button to display the validation error message: