簡體   English   中英

Laravel - 不呈現特定的可呈現異常

[英]Laravel - don't render specific renderable exception

Laravel 具有可呈現的異常,如果它們被拋出(如 ModelNotFoundException、AuthenticationException、ValidationException),則默認呈現這些異常。 有沒有辦法防止這種默認行為?

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). 但我需要 Laravel 將其作為正常的、不可渲染的異常處理。

使用find而不是findOrFail

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

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

// do other stuff here

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM