repository = $forum; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(ForumUserWebRequest $request) { $this->repository->pushCriteria(new \Lavalite\Forum\Repositories\Criteria\ForumUserCriteria()); $forums = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('forum::forum.names').' :: '); return $this->theme->of('forum::user.forum.index', compact('forums'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Forum $forum * * @return Response */ public function show(ForumUserWebRequest $request, Forum $forum) { Form::populate($forum); return $this->theme->of('forum::user.forum.show', compact('forum'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(ForumUserWebRequest $request) { $forum = $this->repository->newInstance([]); Form::populate($forum); return $this->theme->of('forum::user.forum.create', compact('forum'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(ForumUserWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $forum = $this->repository->create($attributes); return redirect(trans_url('/user/forum/forum')) -> with('message', trans('messages.success.created', ['Module' => trans('forum::forum.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Forum $forum * * @return Response */ public function edit(ForumUserWebRequest $request, Forum $forum) { Form::populate($forum); return $this->theme->of('forum::user.forum.edit', compact('forum'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Forum $forum * * @return Response */ public function update(ForumUserWebRequest $request, Forum $forum) { try { $this->repository->update($request->all(), $forum->getRouteKey()); return redirect(trans_url('/user/forum/forum')) ->with('message', trans('messages.success.updated', ['Module' => trans('forum::forum.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(ForumUserWebRequest $request, Forum $forum) { try { $this->repository->delete($forum->getRouteKey()); return redirect(trans_url('/user/forum/forum')) ->with('message', trans('messages.success.deleted', ['Module' => trans('forum::forum.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }