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