public function store(Request $request)
{
$this->validate($request, [
'new_house_id' => 'required|integer',
'is_thinking' => 'required|max:32',
'around_score' => 'required|in:0,1,2,3,4,5',
'traffic_score' => 'required|in:0,1,2,3,4,5',
'green_score' => 'required|in:0,1,2,3,4,5',
'desc' => 'required|min:6|max:255'
], [], [
'new_house_id' => '新房',
'is_thinking' => '是否考虑',
'around_score' => '周边配套',
'traffic_score' => '交通方便',
'green_score' => '绿化环境',
'desc' => '点评'
]);
$comment = $this->commentRepository->store($request->all());
return response()->json(['msg' => '添加评论成功,审核成功后才会显示哦~']);
}
这个是ajax请求的控制器方法,在validate验证不通过是,返回422响应