Search the Community
Showing results for tags 'array key'.
-
Hi, I am building a restfull service and i would like to out put a error like the following { "error": true, "message": "Validation failed", "code": 400, "errors": [ { "field": "first_name", "error": "The first name field is required." }, { "field": "first_name", "error": "The last name field is required." }, { "field": "first_name", "error": "The gender field is required." }, { "field": "first_name", "error": "The city id field is required." }, { "field": "first_name", "error": "The postcode field is required." }, { "field": "first_name", "error": "The email field is required." }, { "field": "first_name", "error": "The password field is required." } ] } but i cant seem to read the array key as what the vailidation failed on $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { $errors = array(); $messages = $validator->messages(); //print_r($messages); foreach ($messages->all() as $value) { $errors[] = array('field' => 'first_name', 'error' => $value ); } $response = Response::json(array( 'error' => true, 'message' => 'Validation failed', 'code' => 400, 'errors' => $errors ) ); //$validator->messages() return $response; }