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