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