Support the ongoing development of Laravel.io →
Forms Validation Input

Hi all

I have two table in DB : companies and shop, both of them have name fields .

And I want to add new Company and it's shops in one form. So in my form I have 2 kinds of model (company and shops).

For echo validation message in this form. I decleared $rules array in each model's class ( Company and Shop). My problem is both of them have the same field called name ( which are company name and shop name). When have both 2 object in one form, the error message which is returned from StoreController will have the same 'name' element in errors array. So, How can I separate Company name error and Shop name error to display error messages ?

Last updated 3 years ago.
0

You can use custom validation attributes to define how to convert any attribute to the string that you want to display in error message

'attributes' => array(
        'name_company' => 'Company name',
        'name_shop' => 'Shop name'
),
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

chungth chungth Joined 7 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.