repository = $payment; parent::__construct(); } /** * Display a list of payment. * * @return Response */ public function index(PaymentRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('payment::payment.names').' :: '); return $this->theme->of('payment::admin.payment.index')->render(); } /** * Display a list of payment. * * @return Response */ public function getJson(PaymentRequest $request) { $pageLimit = $request->input('pageLimit'); $payments = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Asadi\\Payment\\Repositories\\Presenter\\PaymentListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $payments['recordsTotal'] = $payments['meta']['pagination']['total']; $payments['recordsFiltered'] = $payments['meta']['pagination']['total']; $payments['request'] = $request->all(); return response()->json($payments, 200); } /** * Display payment. * * @param Request $request * @param Model $payment * * @return Response */ public function show(PaymentRequest $request, Payment $payment) { if (!$payment->exists) { return response()->view('payment::admin.payment.new', compact('payment')); } Form::populate($payment); return response()->view('payment::admin.payment.show', compact('payment')); } /** * Show the form for creating a new payment. * * @param Request $request * * @return Response */ public function create(PaymentRequest $request) { $payment = $this->repository->newInstance([]); Form::populate($payment); return response()->view('payment::admin.payment.create', compact('payment')); } /** * Create new payment. * * @param Request $request * * @return Response */ public function store(PaymentRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $payment = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('payment::payment.name')]), 'code' => 204, 'redirect' => trans_url('/admin/payment/payment/'.$payment->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show payment for editing. * * @param Request $request * @param Model $payment * * @return Response */ public function edit(PaymentRequest $request, Payment $payment) { Form::populate($payment); return response()->view('payment::admin.payment.edit', compact('payment')); } /** * Update the payment. * * @param Request $request * @param Model $payment * * @return Response */ public function update(PaymentRequest $request, Payment $payment) { try { $attributes = $request->all(); $payment->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('payment::payment.name')]), 'code' => 204, 'redirect' => trans_url('/admin/payment/payment/'.$payment->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/payment/payment/'.$payment->getRouteKey()), ], 400); } } /** * Remove the payment. * * @param Model $payment * * @return Response */ public function destroy(PaymentRequest $request, Payment $payment) { try { $t = $payment->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('payment::payment.name')]), 'code' => 202, 'redirect' => trans_url('/admin/payment/payment/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/payment/payment/'.$payment->getRouteKey()), ], 400); } } }