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