repository = $events; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(EventsUserRequest $request) { $this->repository->pushCriteria(new \Lavalite\Calendar\Repositories\Criteria\EventsUserCriteria()); $events = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('calendar::events.names').' :: '); return $this->theme->of('calendar::user.events.index', compact('events'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Events $events * * @return Response */ public function show(EventsUserRequest $request, Events $events) { Form::populate($events); return $this->theme->of('calendar::user.events.show', compact('events'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(EventsUserRequest $request) { $events = $this->repository->newInstance([]); Form::populate($events); return $this->theme->of('calendar::user.events.create', compact('events'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(EventsUserRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $events = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('calendar::events.name')]); $this->responseRedirect = trans_url('/user/calendar/events'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Events $events * * @return Response */ public function edit(EventsUserRequest $request, Events $events) { Form::populate($events); return $this->theme->of('calendar::user.events.edit', compact('events'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Events $events * * @return Response */ public function update(EventsUserRequest $request, Events $events) { try { $this->repository->update($request->all(), $events->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('calendar::events.name')]); $this->responseRedirect = trans_url('/user/calendar/events'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(EventsUserRequest $request, Events $events) { try { $this->repository->delete($events->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('calendar::events.name')]); $this->responseRedirect = trans_url('/user/calendar/events'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }