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) { return $this->repository ->setPresenter(\Bixo\Discussion\Repositories\Presenter\DiscussionPresenter::class) ->paginate(); } /** * Display discussion. * * @param Request $request * @param Model $discussion * * @return Response */ public function show(DiscussionRequest $request, Discussion $discussion) { return $discussion->setPresenter(\Bixo\Discussion\Repositories\Presenter\DiscussionListPresenter::class); ; } /** * Create new discussion. * * @param Request $request * * @return Response */ public function store(DiscussionRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('discussion::discussion.name')]); $code = 204; $status = 'success'; $url = guard_url('discussion/discussion/' . $discussion->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('discussion/discussion'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the discussion. * * @param Request $request * @param Model $discussion * * @return Response */ public function update(DiscussionRequest $request, Discussion $discussion) { try { $data = $request->all(); $discussion->update($data); $message = trans('messages.success.updated', ['Module' => trans('discussion::discussion.name')]); $code = 204; $status = 'success'; $url = guard_url('discussion/discussion/' . $discussion->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('discussion/discussion/' . $discussion->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the discussion. * * @param Model $discussion * * @return Response */ public function destroy(DiscussionRequest $request, Discussion $discussion) { try { $discussion->delete(); $message = trans('messages.success.deleted', ['Module' => trans('discussion::discussion.name')]); $code = 202; $status = 'success'; $url = guard_url('discussion/discussion/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('discussion/discussion/' . $discussion->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }