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