safriansah

laravel-crud-destroy

Sep 27th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. public function destroy(Request $request)
  2. {
  3.     //
  4.     try {
  5.         //code...
  6.         $validator = Validator::make($request->all(), [
  7.             'id' => 'required|numeric',
  8.             'id_user' => 'required|numeric',
  9.         ]);
  10.  
  11.         if ($validator->fails()) {
  12.             return $this->getResponse(406, $validator->errors()->first());
  13.         }
  14.  
  15.         $transactions = Transactions::where('id', $request->id)->where('id_user', $request->id_user)->first();
  16.  
  17.         if ($transactions) {
  18.             # code...
  19.            $transactions->delete();
  20.  
  21.             return $this->getResponse(200);
  22.         }
  23.         else {
  24.             return $this->getResponse(404);
  25.         }
  26.     } catch (\Throwable $th) {
  27.         //throw $th;
  28.         return $this->getResponse(500, $th);
  29.     }
  30. }
Add Comment
Please, Sign In to add comment