repository = $demo; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Demo\Repositories\Criteria\DemoResourceCriteria::class); } /** * Display a list of demo. * * @return Response */ public function index(DemoRequest $request) { return $this->repository ->setPresenter(\Litecms\Demo\Repositories\Presenter\DemoPresenter::class) ->paginate(); } /** * Display demo. * * @param Request $request * @param Model $demo * * @return Response */ public function show(DemoRequest $request, Demo $demo) { return $demo->setPresenter(\Litecms\Demo\Repositories\Presenter\DemoListPresenter::class); ; } /** * Create new demo. * * @param Request $request * * @return Response */ public function store(DemoRequest $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('demo::demo.name')]); $code = 204; $status = 'success'; $url = guard_url('demo/demo/' . $demo->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('demo/demo'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the demo. * * @param Request $request * @param Model $demo * * @return Response */ public function update(DemoRequest $request, Demo $demo) { try { $data = $request->all(); $demo->update($data); $message = trans('messages.success.updated', ['Module' => trans('demo::demo.name')]); $code = 204; $status = 'success'; $url = guard_url('demo/demo/' . $demo->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('demo/demo/' . $demo->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the demo. * * @param Model $demo * * @return Response */ public function destroy(DemoRequest $request, Demo $demo) { try { $demo->delete(); $message = trans('messages.success.deleted', ['Module' => trans('demo::demo.name')]); $code = 202; $status = 'success'; $url = guard_url('demo/demo/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('demo/demo/' . $demo->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); } }