Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ggalinec's avatar

Single request, multiple models of the same type

I have a situation where user needs to fill one form that has student and partner information. I have to validate both at the same time and display errors - it's the same model that's duplicated.

Here is an example for the data I receive.

https://pastebin.com/w6j0R7sK

I have a RegisterRequest that looks like this,

public function rules() {
    return [
        'Email' => 'required|string|email|max:100|unique:students,Email',
        'Password' => 'required|string|min:4|confirmed',
        'FirstName' => 'required|string|max:100',
        'LastName' => 'required|string|max:100',
        'PhoneHome' => 'required|string|max:100',
        'PhoneCell' => 'string|max:100',
        'MaleFemale' => 'required|string|max:100',
        'Street' => 'required|string|max:100',
        'Apt' => 'string|max:100',
        'City' => 'required|string|max:100',
        'Postal' => 'required|string|max:100',
        'Date' => 'required|string|max:100',
    ];
}
0 likes
3 replies
Drfraker's avatar

Create your form with name prefixes for each field. Like student_email, partner_email, etc. When you do validation you can validate them correctly.

ggalinec's avatar

I've got the form sorted out, that's not the problem. Validation and error display is.

I've got form names like this

name="student[Email]" name="partner[Email]"

I get the data separated as you can see in the pastebin link above ^^

shez1983's avatar

then your request should be student.Email and not just email.

1 like

Please or to participate in this conversation.