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