repository = $circular; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \College\Circular\Repositories\Criteria\CircularUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(CircularRequest $request) { $circulars = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('circular::circular.names')); return $this->theme->of('circular::user.circular.index', compact('circulars'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Circular $circular * * @return Response */ public function show(CircularRequest $request, Circular $circular) { Form::populate($circular); return $this->theme->of('circular::user.circular.show', compact('circular'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(CircularRequest $request) { $circular = $this->repository->newInstance([]); Form::populate($circular); $this->theme->prependTitle(trans('circular::circular.names')); return $this->theme->of('circular::user.circular.create', compact('circular'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(CircularRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $circular = $this->repository->create($attributes); return redirect(trans_url('/user/circular/circular')) -> with('message', trans('messages.success.created', ['Module' => trans('circular::circular.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 Circular $circular * * @return Response */ public function edit(CircularRequest $request, Circular $circular) { Form::populate($circular); $this->theme->prependTitle(trans('circular::circular.names')); return $this->theme->of('circular::user.circular.edit', compact('circular'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Circular $circular * * @return Response */ public function update(CircularRequest $request, Circular $circular) { try { $this->repository->update($request->all(), $circular->getRouteKey()); return redirect(trans_url('/user/circular/circular')) ->with('message', trans('messages.success.updated', ['Module' => trans('circular::circular.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(CircularRequest $request, Circular $circular) { try { $this->repository->delete($circular->getRouteKey()); return redirect(trans_url('/user/circular/circular')) ->with('message', trans('messages.success.deleted', ['Module' => trans('circular::circular.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }