Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function show(Request $request)
- {
- //
- try {
- //code...
- $param = $request->header('param');
- if ($param) {
- # code...
- $param = json_decode($param, true);
- $validator = Validator::make($param, [
- 'id' => 'numeric',
- 'id_user' => 'numeric',
- 'title' => 'max:255',
- 'min_amount' => 'numeric|min:0',
- 'max_amount' => 'numeric|min:0',
- 'type' => 'in:cr,db',
- 'status' => 'in:0,1',
- 'start_date' => 'date_format:Y-m-d',
- 'end_date' => 'date_format:Y-m-d'
- ]);
- if ($validator->fails()) {
- return $this->getResponse(406, $validator->errors()->first());
- }
- $query = Transactions::query();
- if (isset($param['id'])) $query->where('id', $param['id']);
- if (isset($param['id_user'])) $query->where('id_user', $param['id_user']);
- if (isset($param['title'])) $query->where('title', 'like', '%'.$param['title'].'%');
- if (isset($param['type'])) $query->where('type', $param['type']);
- if (isset($param['status'])) $query->where('status', $param['status']);
- if (isset($param['min_amount'])) $query->where('amount', '>=', $param['min_amount']);
- if (isset($param['max_amount'])) $query->where('amount', '<=', $param['max_amount']);
- if (isset($param['start_date'])) $query->where('date', '>=', $param['start_date']);
- if (isset($param['end_date'])) $query->where('date', '<=', $param['end_date']);
- $transactions = $query->get();
- return $this->getResponse(200, false, $transactions);
- }
- else {
- $transactions = Transactions::all();
- return $this->getResponse(200, false, $transactions);
- }
- } catch (\Throwable $th) {
- //throw $th;
- // dd($th);
- return $this->getResponse(500, $th);
- }
- }
Add Comment
Please, Sign In to add comment