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