repository = $attendance; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Payroll\Attendance\Repositories\Criteria\AttendanceUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(AttendanceRequest $request) { $attendances = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('attendance::attendance.names')); return $this->theme->of('attendance::user.attendance.index', compact('attendances'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Attendance $attendance * * @return Response */ public function show(AttendanceRequest $request, Attendance $attendance) { Form::populate($attendance); return $this->theme->of('attendance::user.attendance.show', compact('attendance'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(AttendanceRequest $request) { $attendance = $this->repository->newInstance([]); Form::populate($attendance); $this->theme->prependTitle(trans('attendance::attendance.names')); return $this->theme->of('attendance::user.attendance.create', compact('attendance'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(AttendanceRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attendance = $this->repository->create($attributes); return redirect(trans_url('/user/attendance/attendance')) -> with('message', trans('messages.success.created', ['Module' => trans('attendance::attendance.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Attendance $attendance * * @return Response */ public function edit(AttendanceRequest $request, Attendance $attendance) { Form::populate($attendance); $this->theme->prependTitle(trans('attendance::attendance.names')); return $this->theme->of('attendance::user.attendance.edit', compact('attendance'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Attendance $attendance * * @return Response */ public function update(AttendanceRequest $request, Attendance $attendance) { try { $this->repository->update($request->all(), $attendance->getRouteKey()); return redirect(trans_url('/user/attendance/attendance')) ->with('message', trans('messages.success.updated', ['Module' => trans('attendance::attendance.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(AttendanceRequest $request, Attendance $attendance) { try { $this->repository->delete($attendance->getRouteKey()); return redirect(trans_url('/user/attendance/attendance')) ->with('message', trans('messages.success.deleted', ['Module' => trans('attendance::attendance.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }