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