douzong3599 2017-04-10 06:27
浏览 104
已采纳

尝试/捕捉不使用laravel 5.4

I know there are a lot of answers there about this question but none of them really helped me.

// update name

Route::put('/profile/update', function(Request $request){
$name = $request->input('name');

   try{
         echo DB::table('users')->where('id',Auth::id())->update(['name' => $name]);
      }
   catch(\Exception $e){
     // do task when error
      echo $e->get_message();
   }
});

I have also tried delete method but that is also not working can you please figure out what is going on. thanks.

  • 写回答

3条回答 默认 最新

  • douluozhan4370 2017-04-10 07:56
    关注

    from your code it seems like the code will never hit the catch which is nothing to do with laravel actually. your issue is a SQL one.

    you're trying to update a record and updating a none-existing row will never fail in SQL. so I suggest to handle the case manually by checking the result value and replacing the try and catch with if else

    BTW @Learner is 100% right about get_message() it's not in laravel as I know replace it in the future with getMessage()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!