Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Try/catch not working with 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.

like image 505
anees Avatar asked Dec 11 '22 12:12

anees


1 Answers

2020 Update

Laravel mostly uses camelCase for nomenclature so use:

   catch(\Exception $e){
     // do task when error
      echo $e->getMessage();
   }

If not then just dump full $e to see it through:

    catch(\Exception $e){
       // do task when error
       dd($e);
    }

snake_case nomenclature is only used for table names in Laravel.

like image 55
Abhay Maurya Avatar answered Jan 02 '23 19:01

Abhay Maurya