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