Я пытаюсь перехватить ModelNotFoundException глобально из класса app \ Exceptions \ Handler, чтобы не проверять его на каждом контроллере.
Но это не работает, хотя работает нормально изнутри контроллера:
try {
$asset = Asset::findOrFail($asset_id);
} catch (Exception $e) {
if ($e instanceof ModelNotFoundException)
{
$model = explode('\\', $e->getModel());
return $this->respondWithRecordNotFound(end($model) . ' record not found');
}
return $this->respondWithGeneralError($e->getMessage());
}
app \ Exceptions \ Handler:
public function render($request, Exception $exception)
{
if ($exception instanceof ModelNotFoundException)
{
$model = explode('\\', $exception->getModel());
return $this->respondWithRecordNotFound(end($model) . ' record not found');
}
return parent::render($request, $exception);
}