repository = $sharzon_test; parent::__construct(); } /** * Display a list of sharzon_test. * * @return json */ public function index(SharzonTestRequest $request) { $sharzon_tests = $this->repository ->setPresenter('\\SharzonTest\\SharzonTest\\Repositories\\Presenter\\SharzonTestListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); $sharzon_tests['code'] = 2000; return response()->json($sharzon_tests) ->setStatusCode(200, 'INDEX_SUCCESS'); } /** * Display sharzon_test. * * @param Request $request * @param Model SharzonTest * * @return Json */ public function show(SharzonTestRequest $request, SharzonTest $sharzon_test) { $sharzon_test = $sharzon_test->presenter(); $sharzon_test['code'] = 2001; return response()->json($sharzon_test) ->setStatusCode(200, 'SHOW_SUCCESS');; } /** * Show the form for creating a new sharzon_test. * * @param Request $request * * @return json */ public function create(SharzonTestRequest $request, SharzonTest $sharzon_test) { $sharzon_test = $sharzon_test->presenter(); $sharzon_test['code'] = 2002; return response()->json($sharzon_test) ->setStatusCode(200, 'CREATE_SUCCESS'); } /** * Create new sharzon_test. * * @param Request $request * * @return json */ public function store(SharzonTestRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.api'); $sharzon_test = $this->repository->create($attributes); $sharzon_test = $sharzon_test->presenter(); $sharzon_test['code'] = 2004; return response()->json($sharzon_test) ->setStatusCode(201, 'STORE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4004, ])->setStatusCode(400, 'STORE_ERROR'); } } /** * Show sharzon_test for editing. * * @param Request $request * @param Model $sharzon_test * * @return json */ public function edit(SharzonTestRequest $request, SharzonTest $sharzon_test) { $sharzon_test = $sharzon_test->presenter(); $sharzon_test['code'] = 2003; return response()-> json($sharzon_test) ->setStatusCode(200, 'EDIT_SUCCESS');; } /** * Update the sharzon_test. * * @param Request $request * @param Model $sharzon_test * * @return json */ public function update(SharzonTestRequest $request, SharzonTest $sharzon_test) { try { $attributes = $request->all(); $sharzon_test->update($attributes); $sharzon_test = $sharzon_test->presenter(); $sharzon_test['code'] = 2005; return response()->json($sharzon_test) ->setStatusCode(201, 'UPDATE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4005, ])->setStatusCode(400, 'UPDATE_ERROR'); } } /** * Remove the sharzon_test. * * @param Request $request * @param Model $sharzon_test * * @return json */ public function destroy(SharzonTestRequest $request, SharzonTest $sharzon_test) { try { $t = $sharzon_test->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('sharzon-test::sharzon_test.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }