samedi 5 mars 2022

Laravel not validating array input

I'm trying to validate some input array fields in Laravel. My application reports back the field is required, even though it has been filled out.

The validation code I have is:

$this->validate($request, [
        'first_name'        => 'required',
        'last_name'         => 'required',
        'telephone'         => 'required',
        'email'             => 'unique:contacts,email,' . $request->id,
        'address'           => 'required',
        'address.0.address_line_1'         => 'required',
    ]);

The posted array is:

Array
(
[0] => Array
    (
        ['address_line_1'] => aa
        ['address_line_2'] => 
        ['city'] => 
        ['county'] => 
        ['postcode'] => 
        ['property_type'] => site
    )

)

My input fields are constructed like so:

address[0]['address_line_1']

I'm getting the validation message error:

The address.0.address line 1 field is required.

Anyone know what's wrong here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire