How to check if validation fail when using form-request in Laravel?
问题 I am trying to write a CRUD for an API. However, when the validation fail, instead of redirecting the user to the home page, I want to return json based response with the errors. I am able to do that using the following code public function store(Request $request) { try { $validator = $this->getValidator($request); if ($validator->fails()) { return $this->errorResponse($validator->errors()->all()); } $asset = Asset::create($request->all()); return $this->successResponse( 'Asset was