dimanche 19 juillet 2020

Show message based on transaction executed successfully in Laravel

I am using transaction in Laravel, I want to show message and redirect to specific route based on whether transaction was successful or not. My transaction code is working but i want to redirect to specific route if transaction is successfull.

try {
   \DB::beginTransaction();
   $rowInserted=InfoUser::create(......);
   \DB::commit();
   } catch (\PDOException $e) {         
    \DB::rollBack();
   return redirect()->back()->withErrors(['error' => $e->getMessage()]);
  }

   if($rowInserted->id > 0){
       $request->session()->flash('message', 'Successfully');
   }else{
       $request->session()->flash('error', 'Error! Please try again');
   }

   return redirect('admin/add'); 


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ZIKPBj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire