repository = $payment; parent::__construct(); } /** * Display a list of payment. * * @return json */ public function index(PaymentRequest $request) { $payments = $this->repository ->setPresenter('\\Asadi\\Payment\\Repositories\\Presenter\\PaymentListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); $payments['code'] = 2000; return response()->json($payments) ->setStatusCode(200, 'INDEX_SUCCESS'); } /** * Display payment. * * @param Request $request * @param Model Payment * * @return Json */ public function show(PaymentRequest $request, Payment $payment) { $payment = $payment->presenter(); $payment['code'] = 2001; return response()->json($payment) ->setStatusCode(200, 'SHOW_SUCCESS');; } /** * Show the form for creating a new payment. * * @param Request $request * * @return json */ public function create(PaymentRequest $request, Payment $payment) { $payment = $payment->presenter(); $payment['code'] = 2002; return response()->json($payment) ->setStatusCode(200, 'CREATE_SUCCESS'); } /** * Create new payment. * * @param Request $request * * @return json */ public function store(PaymentRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.api'); $payment = $this->repository->create($attributes); $payment = $payment->presenter(); $payment['code'] = 2004; return response()->json($payment) ->setStatusCode(201, 'STORE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4004, ])->setStatusCode(400, 'STORE_ERROR'); } } /** * Show payment for editing. * * @param Request $request * @param Model $payment * * @return json */ public function edit(PaymentRequest $request, Payment $payment) { $payment = $payment->presenter(); $payment['code'] = 2003; return response()-> json($payment) ->setStatusCode(200, 'EDIT_SUCCESS');; } /** * Update the payment. * * @param Request $request * @param Model $payment * * @return json */ public function update(PaymentRequest $request, Payment $payment) { try { $attributes = $request->all(); $payment->update($attributes); $payment = $payment->presenter(); $payment['code'] = 2005; return response()->json($payment) ->setStatusCode(201, 'UPDATE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4005, ])->setStatusCode(400, 'UPDATE_ERROR'); } } /** * Remove the payment. * * @param Request $request * @param Model $payment * * @return json */ public function destroy(PaymentRequest $request, Payment $payment) { try { $t = $payment->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('payment::payment.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }