repository = $calendar; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Test\Test\Repositories\Criteria\CalendarResourceCriteria::class); } /** * Display a list of calendar. * * @return Response */ public function index(CalendarRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Test\Test\Repositories\Presenter\CalendarPresenter::class) ->$function(); } $calendars = $this->repository->paginate(); return $this->response->title(trans('test::calendar.names')) ->view('test::calendar.index', true) ->data(compact('calendars')) ->output(); } /** * Display calendar. * * @param Request $request * @param Model $calendar * * @return Response */ public function show(CalendarRequest $request, Calendar $calendar) { if ($calendar->exists) { $view = 'test::calendar.show'; } else { $view = 'test::calendar.new'; } return $this->response->title(trans('app.view') . ' ' . trans('test::calendar.name')) ->data(compact('calendar')) ->view($view, true) ->output(); } /** * Show the form for creating a new calendar. * * @param Request $request * * @return Response */ public function create(CalendarRequest $request) { $calendar = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('test::calendar.name')) ->view('test::calendar.create', true) ->data(compact('calendar')) ->output(); } /** * Create new calendar. * * @param Request $request * * @return Response */ public function store(CalendarRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $calendar = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('test::calendar.name')])) ->code(204) ->status('success') ->url(guard_url('test/calendar/' . $calendar->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/test/calendar')) ->redirect(); } } /** * Show calendar for editing. * * @param Request $request * @param Model $calendar * * @return Response */ public function edit(CalendarRequest $request, Calendar $calendar) { return $this->response->title(trans('app.edit') . ' ' . trans('test::calendar.name')) ->view('test::calendar.edit', true) ->data(compact('calendar')) ->output(); } /** * Update the calendar. * * @param Request $request * @param Model $calendar * * @return Response */ public function update(CalendarRequest $request, Calendar $calendar) { try { $attributes = $request->all(); $calendar->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('test::calendar.name')])) ->code(204) ->status('success') ->url(guard_url('test/calendar/' . $calendar->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('test/calendar/' . $calendar->getRouteKey())) ->redirect(); } } /** * Remove the calendar. * * @param Model $calendar * * @return Response */ public function destroy(CalendarRequest $request, Calendar $calendar) { try { $calendar->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('test::calendar.name')])) ->code(202) ->status('success') ->url(guard_url('test/calendar/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('test/calendar/' . $calendar->getRouteKey())) ->redirect(); } } /** * Remove multiple calendar. * * @param Model $calendar * * @return Response */ public function delete(CalendarRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('test::calendar.name')])) ->status("success") ->code(202) ->url(guard_url('test/calendar')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/test/calendar')) ->redirect(); } } /** * Restore deleted calendars. * * @param Model $calendar * * @return Response */ public function restore(CalendarRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('test::calendar.name')])) ->status("success") ->code(202) ->url(guard_url('/test/calendar')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/test/calendar/')) ->redirect(); } } }