Hello.
Based on the codes shared by you, it seems very similar to me. Using try/catch, in this case, is almost the same as the if/else.
A better approach is to, catch the exception in the Laravel handler (app/Exception/Handler.php). It provides you a centralized place to manage that kind of exceptions.
You should create your own exception too, something like "NotRemovableException" (or what you prefer) and throw that exception from your code.
Fianlly, you can create a method like.
´´´
function deleteIfPossible($model, $relation)
{
if(!$model->$relation->isEmpty())
{
throw new NotRemovableException;
}
}
´´´
Then you can handle the NotRemovableException on you exception handler.
It allows you to use the same exception for different models as well.
Hope it give you some ideas.
Best wishes.