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