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