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