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