2

I have a form that represents two instances of a same Address class (let's say main address and billing address), which in turn inherits from Ardent.

The form is defined as:

Form::model($data, ...)

where:

$data = [ 'mainAddress' => [instance A of Address], 
          'billingAddress' => [instance B of Address] ];

The fields in the form have names that follow an array notation, such as:

Form::text('mainAddress[zipcode]')
...
Form::text('billingAddress[zipcode')

in order to pull out both models with ease with Input::get('mainAddress') and Input::get('billingAddress').

I have some problems to find a concise way to check the validation errors for both the models. Checking both the instances is no big deal, the problem is in the view where I must display the appropriate error next to the field; in normal cases I'd use a simple $errors->has('fieldName'), but with two instances I have problems in pulling out with ease the error message.

Note: I know that a solution would be to flatten the field names (f.ex. mainAddress_zipcode) and define a custom ruleset that comprises the fields of both the instances, but it seems likely that I'm missing a more concise and elegant way to do this.

Cranio
  • 9,647
  • 4
  • 35
  • 55

0 Answers0