form = CalendarForm::setAttributes()->toArray(); $this->modules = $this->modules(config('litepie.calendar.modules'), 'calendar', guard_url('calendar')); $this->repository = $calendar; } /** * Display a list of calendar. * * @return Response */ public function index(CalendarRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(CalendarResourceFilter::class) ->setPresenter(CalendarListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('calendar::calendar.names')) ->view('calendar::calendar.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display calendar. * * @param Request $request * @param Model $calendar * * @return Response */ public function show(CalendarRequest $request, CalendarRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('calendar::calendar.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('calendar::calendar.show') ->output(); } /** * Show the form for creating a new calendar. * * @param Request $request *x * @return Response */ public function create(CalendarRequest $request, CalendarRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('calendar::calendar.name')) ->view('calendar::calendar.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new calendar. * * @param Request $request * * @return Response */ public function store(CalendarRequest $request, CalendarRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('calendar::calendar.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('calendar/calendar/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/calendar/calendar')) ->redirect(); } } /** * Show calendar for editing. * * @param Request $request * @param Model $calendar * * @return Response */ public function edit(CalendarRequest $request, CalendarRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('calendar::calendar.name')) ->view('calendar::calendar.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the calendar. * * @param Request $request * @param Model $calendar * * @return Response */ public function update(CalendarRequest $request, CalendarRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('calendar::calendar.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('calendar/calendar/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('calendar/calendar/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the calendar. * * @param Model $calendar * * @return Response */ public function destroy(CalendarRequest $request, CalendarRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('calendar::calendar.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('calendar/calendar/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('calendar/calendar/' . $repository->getRouteKey())) ->redirect(); } } }