When I write User::findOrFail(100), and id=100 does not exisit. It will throw ModelNotFoundException, message is No query results for model [...]. I want to return code and message using dingp/api in this situation. How to do that?
I tried to add if ($e instanceof ModelNotFoundException) {...} in app/Exceptions/Handle.php render method, it does not work.
I add this to AppServiceProvider.
$this->app->make('api.exception')->register(function (ModelNotFoundException $e) {
return abort(404);
});
@crynobone In AppServiceProvider register method? It tells me api.exception class does not exist
Boot dingo.api before app service provider.
$app->register(Dingo\Api\Provider\LumenServiceProvider::class);
// ...
$app->register(App\Lumen\Providers\AppServiceProvider::class);
And do it in boot, not register.
Most helpful comment
I add this to
AppServiceProvider.