Support the ongoing development of Laravel.io →
posted 10 years ago
Validation

I am using Laravel 4.1.

I am creating an application where a "team" can have multiple "students" associated with it. I am trying to create a form where you can create a team and add multiple students at the same time.

Each student has multiple form fields, IE: first name, last name, email, etc. I have javascript to add new form entries. Form field names are arrays: students[1][first_name], students[1][last_name] and so on, where the index is incremented.

I am able to validate these fields with a simple loop:

    foreach(Input::get('students') as $index => $student) 
    {
          $studentValidation[$index] = Validator::make($student, Student::$rules);
          if($studentValidation[$index]->fails()) 
            {
                 $failed = true;
            }
     }
    if($failed) 
     {
          // The following does no work
          View::make('team.create')->withErrors($studentValidation)
     }

What I would like is for an array of separate errors to be passed to the make function so I can display errors associated with the creation of individual student records by looping through the array of messages.

Is there an obvious way to do this with Laravel 4.1?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

SaintPeter saintpeter Joined 22 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.