repository = $refund; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Cart\Refund\Repositories\Criteria\RefundResourceCriteria::class); } /** * Display a list of refund. * * @return Response */ public function index(RefundRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Cart\Refund\Repositories\Presenter\RefundPresenter::class) ->$function(); } $refunds = $this->repository->paginate(); return $this->response->setMetaTitle(trans('refund::refund.names')) ->view('refund::refund.index', true) ->data(compact('refunds', 'view')) ->output(); } /** * Display refund. * * @param Request $request * @param Model $refund * * @return Response */ public function show(RefundRequest $request, Refund $refund) { if ($refund->exists) { $view = 'refund::refund.show'; } else { $view = 'refund::refund.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('refund::refund.name')) ->data(compact('refund')) ->view($view, true) ->output(); } /** * Show the form for creating a new refund. * * @param Request $request * * @return Response */ public function create(RefundRequest $request) { $refund = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('refund::refund.name')) ->view('refund::refund.create', true) ->data(compact('refund')) ->output(); } /** * Create new refund. * * @param Request $request * * @return Response */ public function store(RefundRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $refund = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('refund::refund.name')])) ->code(204) ->status('success') ->url(guard_url('refund/refund/' . $refund->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/refund/refund')) ->redirect(); } } /** * Show refund for editing. * * @param Request $request * @param Model $refund * * @return Response */ public function edit(RefundRequest $request, Refund $refund) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('refund::refund.name')) ->view('refund::refund.edit', true) ->data(compact('refund')) ->output(); } /** * Update the refund. * * @param Request $request * @param Model $refund * * @return Response */ public function update(RefundRequest $request, Refund $refund) { try { $attributes = $request->all(); $refund->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('refund::refund.name')])) ->code(204) ->status('success') ->url(guard_url('refund/refund/' . $refund->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('refund/refund/' . $refund->getRouteKey())) ->redirect(); } } /** * Remove the refund. * * @param Model $refund * * @return Response */ public function destroy(RefundRequest $request, Refund $refund) { try { $refund->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('refund::refund.name')])) ->code(202) ->status('success') ->url(guard_url('refund/refund/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('refund/refund/' . $refund->getRouteKey())) ->redirect(); } } /** * Remove multiple refund. * * @param Model $refund * * @return Response */ public function delete(RefundRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('refund::refund.name')])) ->status("success") ->code(202) ->url(guard_url('refund/refund')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/refund/refund')) ->redirect(); } } /** * Restore deleted refunds. * * @param Model $refund * * @return Response */ public function restore(RefundRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('refund::refund.name')])) ->status("success") ->code(202) ->url(guard_url('/refund/refund')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/refund/refund/')) ->redirect(); } } }