Answer the question
In order to leave comments, you need to log in
Why does findOrFail() work so strangely?
All of a sudden I remembered findOrFail() - and it does indeed throw an exception if it doesn't find the model :) HOWEVER, look at the output:
{
"message": "No query results for model [App\\Models\\User] 9999999",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
Illuminate\Database\Eloquent\ModelNotFoundException
throw (new ModelNotFoundException)->setModel(
get_class($this->model), $id
);
Answer the question
In order to leave comments, you need to log in
$this->renderable(function (NotFoundHttpException $e, $request) {
if ($request->is('users/*')) {
return response()->json([
'message' => 'Юзер не найден'
], 404);
}
});
1. to the question "where did NotFoundHttpException come from..."
src/Illuminate/Foundation/Exceptions/Handler.php
2. if you don't want standard exceptions - don't use findOrFail
2.1 you can't without findOrFail - change the behavior of app/Exceptions/Handler.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question