I have the following code in my model:
public static function boot(){
parent::boot();
// Não deixa excluir caso possua registros vinculados.
static::deleting(function($content_area){
if($total = $content_area->contents->count() > 0){
//throw new Exception("Essa área não pode ser removida, ela possui {$total} conteútos vinculados.");
return App::abort(403, "Essa área não pode ser removida, ela possui {$total} conteútos vinculados.");
}
});
}
In my controller I have the following:
public function destroy($id){
$content_area = ContentArea::find($id);
try {
$content_area->delete();
} catch (Exception $e) {
return Response::json(
[
'success' => 'false',
'message' => $e->getMessage(),
'messageType' => 'error'
]
);
}
return Response::json(['success' => false]);
}
Theoretically, during log deletion, it should throw the exception if the condition is true within the observer.
The problem is that it shows the Laravel exceptions screen and kills the application. I did not want this to happen, I wanted it to just return the message for me to display to the user. Does anyone know why this is happening?