abort() helper explained
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abort( | |
response()->json(['message' => 'Ooops!.'], 402) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"message": "Ooops!." | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Handler implements ExceptionHandlerContract | |
{ | |
//... | |
public function render($request, Exception $e) | |
{ | |
if (method_exists($e, 'render') && $response = $e->render($request)) { | |
return Router::toResponse($request, $response); | |
} elseif ($e instanceof Responsable) { | |
return $e->toResponse($request); | |
} | |
$e = $this->prepareException($e); | |
if ($e instanceof HttpResponseException) { | |
return $e->getResponse(); | |
} elseif ($e instanceof AuthenticationException) { | |
return $this->unauthenticated($request, $e); | |
} elseif ($e instanceof ValidationException) { | |
return $this->convertValidationExceptionToResponse($e, $request); | |
} | |
return $request->expectsJson() | |
? $this->prepareJsonResponse($request, $e) | |
: $this->prepareResponse($request, $e); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (! function_exists('abort')) { | |
/** | |
* Throw an HttpException with the given data. | |
* | |
* @param \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Support\Responsable|int $code | |
* @param string $message | |
* @param array $headers | |
* @return void | |
* | |
* @throws \Symfony\Component\HttpKernel\Exception\HttpException | |
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException | |
*/ | |
function abort($code, $message = '', array $headers = []) | |
{ | |
if ($code instanceof Response) { | |
throw new HttpResponseException($code); | |
} elseif ($code instanceof Responsable) { | |
throw new HttpResponseException($code->toResponse(request())); | |
} | |
app()->abort($code, $message, $headers); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment