LARAVEL

Form Array Validation in Laravel 5.2


This is a series of posts that showcase new features and aha moments in Laravel 5.2

1. Implicit Route Model Binding

2. Simplified Eloquent Global Scopes

3. Append Scheduled Tasks Output

4. Form Array Validation

5. Middleware Groups

6. Auth Scaffolding

7.  Api Rate Limiting

8. More helper functions

Form Array Validation is now a breeze in Laravel 5.2

With a much cleaner and simpler syntax, you can easily validate a form with arrays.

Let’s look at a very practical example right now.

Let’s say you have a form like so:

In this form, you can see we are trying to process Student and Teachers details.

The Student and Teacher information is grouped together separately. There are several situations where your forms become like this.

This is just a typical example.

Laravel 5.2 makes it very easy to process this without sweating!

How?. Simple

In your Controller, say your store method, all you need is something like this:

Viola!!..Laravel internally processes the two arrays without any effort from our end.

In Laravel 5.1, you will have to loop through the array and add the rules individually.

The * means all, so you can also exchange it with numbers like 1 , 2 , 3 and so depending on the amount of array values you have in your forms.

Please, let me know if you have any questions or observations in the comments section below :smile:

 

PROSPER OTEMUYIWA

About PROSPER OTEMUYIWA

Food Ninja, Code Slinger, Technical Trainer, Accidental Writer, Open Source Advocate and Developer Evangelist.