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