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