Instead of following code:
try{
$model->save();
}catch(\Exception $e){
Log::info('Exception thrown');
}
Try this:
if(!$model->save()) {
throw new Exception("Couldn't save!");
}
else {
// success
}
By default there is (create if not) an exception handler in your app/start/global.php
, like this:
App::error(function(Exception $exception, $code)
{
Log::error($exception);
//Log::error($exception->getMessage());
});
You may also create a custom exception class by extending the base Exception
class and can throw that custom exception instead.
Update: You are saving $model->save();
instead of $new->save();
.
Why didn't it got caught in my catch
It's because a fatal error has occurred and you have a registered handler for fatal errors like one given below and error caught by that handler instead:
App::fatal(function($exception){
//...
return Response::json(...);
});
So, once you send the response from any error handler then it stops propagating to up, just finished the propagating with response sent.