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