Skip to content

Instantly share code, notes, and snippets.

@argentinaluiz
Created January 6, 2020 02:40
Show Gist options
  • Save argentinaluiz/6a6a94e9a231fccd0b0fedf9ba82ec94 to your computer and use it in GitHub Desktop.
Save argentinaluiz/6a6a94e9a231fccd0b0fedf9ba82ec94 to your computer and use it in GitHub Desktop.
Format HTTP response with Laravel
public function render($request, Exception $exception)
{
if ($exception instanceof ModelNotFoundException && $request->isJson()) {
$mensagens = [
User::class => 'Usuario não encontrado',
Product:class => 'Produto não encontrado'
}
$mensagem = $mensagens[$exception->getModel()]
return response()->json($mensagem, 404);
}
return parent::render($request, $exception);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment