I have Controller.phpwhose method show($id)gets along the route.
public function show($id)
{
$this->checkEverythingIsOk($attributes);
return $response;
}
Now, in checkEverythingIsOk(), I perform some actions for verification and authorization. These checks are common to several routes within the same controller, so I would like to extract these checks and call the method every time I need to perform the same operations.
The problem is that I cannot send some answers from this method:
private function checkEverythingIsOk($attributes)
{
if (checkSomething()) {
return response()->json('Something went wrong');
}
return response()->callAResponseMacro('Something else went wrong');
dd($attributes);
abort(422);
}
Note. Yes, I know that in the general case, you can use the middleware or verification services to perform checks before the request reaches the controller, but I do not want to do this. I need to do it this way.