repository = $demo; parent::__construct(); } /** * Display a list of demo. * * @return Response */ public function index(DemoAdminWebRequest $request) { if ($request->wantsJson()) { $demos = $this->repository->setPresenter('\\Litecms\\Demorequest\\Repositories\\Presenter\\DemoListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); return response()->json($demos, 200); } $this ->theme->prependTitle(trans('demorequest::demo.names').' :: '); return $this->theme->of('demorequest::admin.demo.index')->render(); } /** * Display demo. * * @param Request $request * @param Model $demo * * @return Response */ public function show(DemoAdminWebRequest $request, Demo $demo) { if (!$demo->exists) { return response()->view('demorequest::admin.demo.new', compact('demo')); } Form::populate($demo); return response()->view('demorequest::admin.demo.show', compact('demo')); } /** * Show the form for creating a new demo. * * @param Request $request * * @return Response */ public function create(DemoAdminWebRequest $request) { $demo = $this->repository->newInstance([]); Form::populate($demo); return response()->view('demorequest::admin.demo.create', compact('demo')); } /** * Create new demo. * * @param Request $request * * @return Response */ public function store(DemoAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $demo = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('demorequest::demo.name')]), 'code' => 204, 'redirect' => trans_url('/admin/demorequest/demo/'.$demo->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show demo for editing. * * @param Request $request * @param Model $demo * * @return Response */ public function edit(DemoAdminWebRequest $request, Demo $demo) { Form::populate($demo); return response()->view('demorequest::admin.demo.edit', compact('demo')); } /** * Update the demo. * * @param Request $request * @param Model $demo * * @return Response */ public function update(DemoAdminWebRequest $request, Demo $demo) { try { $attributes = $request->all(); $demo->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('demorequest::demo.name')]), 'code' => 204, 'redirect' => trans_url('/admin/demorequest/demo/'.$demo->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/demorequest/demo/'.$demo->getRouteKey()), ], 400); } } /** * Remove the demo. * * @param Model $demo * * @return Response */ public function destroy(DemoAdminWebRequest $request, Demo $demo) { try { $t = $demo->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('demorequest::demo.name')]), 'code' => 202, 'redirect' => trans_url('/admin/demorequest/demo/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/demorequest/demo/'.$demo->getRouteKey()), ], 400); } } }