model = $demo; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(DemoAdminRequest $request) { if ($request->wantsJson()) { $array = $this->model->json(); foreach ($array as $key => $row) { $array[$key] = array_only($row, config('demo.demo.listfields')); } return ['data' => $array]; } $this->theme->prependTitle(trans('demo::demo.names').' :: '); return $this->theme->of('demo::admin.demo.index')->render(); } /** * Display the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function show(DemoAdminRequest $request, $id) { $demo = $this->model->find($id); if (empty($demo)) { if ($request->wantsJson()) { return []; } return view('demo::admin.demo.new'); } if ($request->wantsJson()) { return $demo; } Former::populate($demo); return view('demo::admin.demo.show', compact('demo')); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(DemoAdminRequest $request) { $demo = $this->model->findOrNew(0); Former::populate($demo); return view('demo::admin.demo.create', compact('demo')); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(DemoAdminRequest $request) { try { $attributes = $request->all(); $demo = $this->model->create($attributes); return $this->success(trans('messages.success.created', ['Module' => trans('demo::demo.name')])); } catch (Exception $e) { return $this->error($e->getMessage()); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function edit(DemoAdminRequest $request, $id) { $demo = $this->model->find($id); Former::populate($demo); return view('demo::admin.demo.edit', compact('demo')); } /** * Update the specified resource. * * @param Request $request * @param int $id * * @return Response */ public function update(DemoAdminRequest $request, $id) { try { $attributes = $request->all(); $demo = $this->model->update($attributes, $id); return $this->success(trans('messages.success.updated', ['Module' => trans('demo::demo.name')])); } catch (Exception $e) { return $this->error($e->getMessage()); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(DemoAdminRequest $request, $id) { try { $this->model->delete($id); return $this->success(trans('message.success.deleted', ['Module' => trans('demo::demo.name')]), 200); } catch (Exception $e) { return $this->error($e->getMessage()); } } }