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