Created
January 6, 2020 02:40
-
-
Save argentinaluiz/6a6a94e9a231fccd0b0fedf9ba82ec94 to your computer and use it in GitHub Desktop.
Format HTTP response with Laravel
This file contains hidden or 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
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