Im just move to laravel 5 and im receiving errors from laravel in HTML page. Something like this:
Sorry, the page you are looking for could not be found.
1/1
NotFoundHttpException in Application.php line 756:
Persona no existe
in Application.php line 756
at Application->abort('404', 'Person doesnt exists', array()) in helpers.php line
When i work with laravel 4 all works fine, the errors are in json format, that way i could parse the error message and show a message to the user. An example of json error:
{"error":{
"type":"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
"message":"Person doesnt exist",
"file":"C:\\xampp\\htdocs\\backend1\\bootstrap\\compiled.php",
"line":768}}
How can i achieve that in laravel 5.
Sorry for my bad english, thanks a lot.
abort
(and relatedabort_if
,abort_unless
) with a customResponse
object (in the place where you'd put the status code) if you need more control than the options provided by theabort
function. For example, if you need a JSON response (and cannot set the accept header toapplication/json
), you could doabort(new JsonResponse('A JSON string, could also be an array etc.', 403, ['Optional' => 'Headers'])
– Uella