repository = $calendars; } /** * Display a list of calendars. * * @return Response */ public function index(CalendarsAdminRequest $request) { $calendars = $this->repository->setPresenter('\\Emixion\\Calendar\\Repositories\\Presenter\\CalendarsListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this ->theme->prependTitle(trans('calendar::calendars.names').' :: '); $view = $this->theme->of('calendar::admin.calendars.index')->render(); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('calendar::calendars.name')]); $this->responseData = $calendars['data']; $this->responseMeta = $calendars['meta']; $this->responseView = $view; $this->responseRedirect = ''; return $this->respond($request); } /** * Display calendars. * * @param Request $request * @param int $id * * @return Response */ public function show(CalendarsAdminRequest $request, Calendars $calendars) { if (!$calendars->exists) { $this->responseCode = 404; $this->responseMessage = trans('messages.success.notfound', ['Module' => trans('calendar::calendars.name')]); $this->responseView = view('calendar::admin.calendars.new'); return $this -> respond($request); } Form::populate($calendars); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('calendar::calendars.name')]); $this->responseData = $calendars; $this->responseView = view('calendar::admin.calendars.show', compact('calendars')); return $this -> respond($request); } /** * Show the form for creating a new calendars. * * @param Request $request * * @return Response */ public function create(CalendarsAdminRequest $request) { $calendars = $this->repository->newInstance([]); Form::populate($calendars); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('calendar::calendars.name')]); $this->responseData = $calendars; $this->responseView = view('calendar::admin.calendars.create', compact('calendars')); return $this -> respond($request); } /** * Create new calendars. * * @param Request $request * * @return Response */ public function store(CalendarsAdminRequest $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->responseData = $calendars; $this->responseMeta = ''; $this->responseRedirect = trans_url('/admin/calendar/calendars/'.$calendars->getRouteKey()); $this->responseView = view('calendar::admin.calendars.create', compact('calendars')); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this -> respond($request); } } /** * Show calendars for editing. * * @param Request $request * @param int $id * * @return Response */ public function edit(CalendarsAdminRequest $request, Calendars $calendars) { Form::populate($calendars); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('calendar::calendars.name')]); $this->responseData = $calendars; $this->responseView = view('calendar::admin.calendars.edit', compact('calendars')); return $this -> respond($request); } /** * Update the calendars. * * @param Request $request * @param int $id * * @return Response */ public function update(CalendarsAdminRequest $request, Calendars $calendars) { try { $attributes = $request->all(); $calendars->update($attributes); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('calendar::calendars.name')]); $this->responseData = $calendars; $this->responseRedirect = trans_url('/admin/calendar/calendars/'.$calendars->getRouteKey()); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/calendar/calendars/'.$calendars->getRouteKey()); return $this -> respond($request); } } /** * Remove the calendars. * * @param int $id * * @return Response */ public function destroy(CalendarsAdminRequest $request, Calendars $calendars) { try { $t = $calendars->delete(); $this->responseCode = 202; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('calendar::calendars.name')]); $this->responseRedirect = trans_url('/admin/calendar/calendars/0'); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/calendar/calendars/'.$calendars->getRouteKey()); return $this -> respond($request); } } }