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