repository = $event; parent::__construct(); } /** * Display a list of event. * * @return Response */ public function index(EventRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('test::event.names')); return $this->theme->of('test::admin.event.index')->render(); } /** * Display a list of event. * * @return Response */ public function getJson(EventRequest $request) { $pageLimit = $request->input('pageLimit'); $events = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Test\\Test\\Repositories\\Presenter\\EventListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $events['recordsTotal'] = $events['meta']['pagination']['total']; $events['recordsFiltered'] = $events['meta']['pagination']['total']; $events['request'] = $request->all(); return response()->json($events, 200); } /** * Display event. * * @param Request $request * @param Model $event * * @return Response */ public function show(EventRequest $request, Event $event) { if (!$event->exists) { return response()->view('test::admin.event.new', compact('event')); } Form::populate($event); return response()->view('test::admin.event.show', compact('event')); } /** * Show the form for creating a new event. * * @param Request $request * * @return Response */ public function create(EventRequest $request) { $event = $this->repository->newInstance([]); Form::populate($event); return response()->view('test::admin.event.create', compact('event')); } /** * Create new event. * * @param Request $request * * @return Response */ public function store(EventRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $event = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('test::event.name')]), 'code' => 204, 'redirect' => trans_url('/admin/test/event/'.$event->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show event for editing. * * @param Request $request * @param Model $event * * @return Response */ public function edit(EventRequest $request, Event $event) { Form::populate($event); return response()->view('test::admin.event.edit', compact('event')); } /** * Update the event. * * @param Request $request * @param Model $event * * @return Response */ public function update(EventRequest $request, Event $event) { try { $attributes = $request->all(); $event->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('test::event.name')]), 'code' => 204, 'redirect' => trans_url('/admin/test/event/'.$event->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/test/event/'.$event->getRouteKey()), ], 400); } } /** * Remove the event. * * @param Model $event * * @return Response */ public function destroy(EventRequest $request, Event $event) { try { $t = $event->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('test::event.name')]), 'code' => 202, 'redirect' => trans_url('/admin/test/event/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/test/event/'.$event->getRouteKey()), ], 400); } } }