Abdul Marchand
Abdul Marchand

Reputation: 1

Laravel - don't render specific renderable exception

Laravel has renderable exceptions that it renders by default if they were thrown (like ModelNotFoundException, AuthenticationException, ValidationException). Is there a way to prevent this default behavior?

example: if I use the Model::findOrFail($someId) method and there is no model with id $someId, then laravel will show 404 page (because findOrFail method threw a ModelNotFoundException exception). But I need Laravel to process it as a normal, non-renderable exception.

Upvotes: 0

Views: 257

Answers (1)

kjoedion
kjoedion

Reputation: 580

Use find instead of findOrFail:

$model = Model::find($someId);

if ($model) {
  // the model was found
} else {
  // the model was not found
}

// do other stuff here

Upvotes: 1

Related Questions