donglugou6652 2015-05-13 21:33
浏览 55
已采纳

Laravel 5.0模型未找到异常

try {
  $university_exists = University::where('name', '=', $university_name) - > firstOrFail();
} catch (ModelNotFoundException $e) {
  $title = "Error retrieving data";
  $message = "Entered university not found!";
  $success = 0;
  return Response::json(['title' => $title, 'message' => $message, 'success' => $success], 200);
}

The above code works when I give correct university name. When I give wrong university name it throws a model not found exception.

Which I try to catch in the catch block. However, it doesn't get caught.

Can someone help me please?

ModelNotFoundException in Builder.php line 151: No query results for model [App\University].

  • 写回答

1条回答 默认 最新

  • duanche2007 2015-05-13 21:36
    关注

    You probably have to import the exception class with:

    use Illuminate\Database\Eloquent\ModelNotFoundException;
    

    at the top of your file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式