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