Advertisement
safriansah

laravel-crud-store

Sep 27th, 2020
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. public function store(Request $request)
  2. {
  3.     //
  4.     try {
  5.         //code...
  6.         $validator = Validator::make($request->all(), [
  7.             'id_user' => 'required|numeric',
  8.             'title' => 'required|max:255',
  9.             'amount' => 'required|numeric|min:1',
  10.             'type' => 'required|in:cr,db',
  11.             'status' => 'required|in:0,1',
  12.             'date' => 'required|date_format:Y-m-d'
  13.         ]);
  14.  
  15.         if ($validator->fails()) {
  16.             return $this->getResponse(406, $validator->errors()->first());
  17.         }
  18.  
  19.         $transactions = new Transactions;
  20.         $transactions->id_user = $request->id_user;
  21.         $transactions->title = $request->title;
  22.         $transactions->amount = $request->amount;
  23.         $transactions->type = $request->type;
  24.         $transactions->status = $request->status;
  25.         $transactions->date = $request->date;
  26.         $transactions->save();
  27.  
  28.         return $this->getResponse(200);
  29.     } catch (\Throwable $th) {
  30.         //throw $th;
  31.         return $this->getResponse(500, $th);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement