Skip to content

Instantly share code, notes, and snippets.

@aquasmit
Created December 19, 2016 03:44
Show Gist options
  • Save aquasmit/1d38083f80f216dac7f3a68040740e7e to your computer and use it in GitHub Desktop.
Save aquasmit/1d38083f80f216dac7f3a68040740e7e to your computer and use it in GitHub Desktop.
Laravel - Try Catch FindOrFail Exceptions

Following should work if you want to use try/catch for FindOrFail

use Illuminate\Database\Eloquent\ModelNotFoundException;
...
try {
  $current = Promovote::where('module_id',$data['module'])->firstOrFail($id);
} catch (ModelNotFoundException $ex) {
  // Error handling code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment