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