octoxan's avatar

Okay to ignore this PHP Storm / Laravel error?

When writing the following code in PHPStorm it warns "Unhandled \Exception":

Flight::where('flight_number', $flight_number)->delete();

Is there some way I should be writing this differently? In my case it's not at all an issue if the record isn't deleted.

I believe this won't even error out if something isn't found to be deleted, correct? Just ignore this PHPStorm inspection? Seems to be firing on every delete method I've ever called. >.>

0 likes
2 replies
bobbybouwmann's avatar
Level 88

Well PHPStorm is complaining about it because it doesn't see any catch method for the exception and it's also not specified in the doc blocks. However every exception in Laravel is handled in the Handler.php class and therefore you don't have to catch it, unless you want to perform some action on failure of course.

You don't have to do anything here, PHPStorm is just warning you. You can also turn it off if you wish!

1 like
dyoung@volume9inc.com's avatar

If I remember correctly, it's been a bit since I've used PHP Storm, this means that either the where() or the the delete() have throws exception statements which should be wrapped in a try/catch. Wrap the line in a try/catch and it should clear up.

Please or to participate in this conversation.