参考 http://laravelacademy.org/post/3279.html
use Validator;
$rules =array(
'proj' => 'required',
'dDate' => 'required|date',
'rDate' => 'date',
);
$messages = [
'proj.required' => 'Project can not be empty',
'dDate.required' => 'Due Date can not be empty',
];
$validator = Validator::make($request->input('data'), $rules, $messages);
if ($validator->fails()) {
$error = $validator->errors();
$error = json_decode($error, true);
$error_arr = array();
foreach ($error as $k => $v){
$error_arr['data'][$k] = $v[0];
}
$error_message = json_encode($error_arr);
if(!empty($error_arr['data'])){
return $this->response->error($error_message, 406);
exit();
}
}