repository = $calendar; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\Calendar\Repositories\Criteria\CalendarResourceCriteria::class); } /** * Display a list of calendar. * * @return Response */ public function index(CalendarRequest $request) { return $this->repository ->setPresenter(\Litepie\Calendar\Repositories\Presenter\CalendarPresenter::class) ->paginate(); } /** * Display calendar. * * @param Request $request * @param Model $calendar * * @return Response */ public function show(CalendarRequest $request, Calendar $calendar) { return $calendar->setPresenter(\Litepie\Calendar\Repositories\Presenter\CalendarListPresenter::class); ; } /** * Create new calendar. * * @param Request $request * * @return Response */ public function store(CalendarRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('calendar::calendar.name')]); $code = 204; $status = 'success'; $url = guard_url('calendar/calendar/' . $calendar->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('calendar/calendar'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the calendar. * * @param Request $request * @param Model $calendar * * @return Response */ public function update(CalendarRequest $request, Calendar $calendar) { try { $data = $request->all(); $calendar->update($data); $message = trans('messages.success.updated', ['Module' => trans('calendar::calendar.name')]); $code = 204; $status = 'success'; $url = guard_url('calendar/calendar/' . $calendar->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('calendar/calendar/' . $calendar->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the calendar. * * @param Model $calendar * * @return Response */ public function destroy(CalendarRequest $request, Calendar $calendar) { try { $calendar->delete(); $message = trans('messages.success.deleted', ['Module' => trans('calendar::calendar.name')]); $code = 202; $status = 'success'; $url = guard_url('calendar/calendar/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('calendar/calendar/' . $calendar->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }