mercredi 16 novembre 2016

messageBag with array L5.1

I'm getting this error message bag from a RESTfull API on a Laravel client, I want to show the errors to the user, but I'm having trouble to show the errors inside the bag when they are an array.

MessageBag {#251 ▼
  #messages: array:6 [▼
    "gender" => array:1 [▶]
    "first_name" => array:1 [▼
      0 => "The first name must be at least 2 characters."
    ]
    "last_name" => array:1 [▶]
    "user_id" => array:1 [▶]
    0 => array:4 [▼
      "user_id" => array:1 [▶]
      "address2" => array:1 [▼
        0 => "The address2 must be at least 3 characters."
      ]
      "zip" => array:1 [▶]
      "phone" => array:1 [▶]
    ]
    1 => array:4 [▼
      "user_id" => array:1 [▶]
      "address2" => array:1 [▼
        0 => "The address2 must be at least 3 characters."
      ]
      "zip" => array:1 [▶]
      "phone" => array:1 [▶]
    ]
  ]
  #format: ":message"
}

I know the normal way to show errors for example to print the gender errors I can do this one:

{!! $errors->first('gender', '<label class="control-label"><i class="glyphicon glyphicon-menu"></i> :message</label>') !!} 

Or to check if 'gender' error exists:

{!! $errors->has('gender') ? 'has-error' : '' !!}

But how I do to check if the array 0 exists and show the errors?

Thank you :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire