repository = $working; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Hrm\Timesheet\Repositories\Criteria\WorkingResourceCriteria::class); } /** * Display a list of working. * * @return Response */ public function index(WorkingRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Hrm\Timesheet\Repositories\Presenter\WorkingPresenter::class) ->$function(); } $workings = $this->repository->paginate(); return $this->response->setMetaTitle(trans('timesheet::working.names')) ->view('timesheet::working.index', true) ->data(compact('workings', 'view')) ->output(); } /** * Display working. * * @param Request $request * @param Model $working * * @return Response */ public function show(WorkingRequest $request, Working $working) { if ($working->exists) { $view = 'timesheet::working.show'; } else { $view = 'timesheet::working.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('timesheet::working.name')) ->data(compact('working')) ->view($view, true) ->output(); } /** * Show the form for creating a new working. * * @param Request $request * * @return Response */ public function create(WorkingRequest $request) { $working = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('timesheet::working.name')) ->view('timesheet::working.create', true) ->data(compact('working')) ->output(); } /** * Create new working. * * @param Request $request * * @return Response */ public function store(WorkingRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $working = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('timesheet::working.name')])) ->code(204) ->status('success') ->url(guard_url('timesheet/working/' . $working->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/timesheet/working')) ->redirect(); } } /** * Show working for editing. * * @param Request $request * @param Model $working * * @return Response */ public function edit(WorkingRequest $request, Working $working) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('timesheet::working.name')) ->view('timesheet::working.edit', true) ->data(compact('working')) ->output(); } /** * Update the working. * * @param Request $request * @param Model $working * * @return Response */ public function update(WorkingRequest $request, Working $working) { try { $attributes = $request->all(); $working->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('timesheet::working.name')])) ->code(204) ->status('success') ->url(guard_url('timesheet/working/' . $working->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('timesheet/working/' . $working->getRouteKey())) ->redirect(); } } /** * Remove the working. * * @param Model $working * * @return Response */ public function destroy(WorkingRequest $request, Working $working) { try { $working->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('timesheet::working.name')])) ->code(202) ->status('success') ->url(guard_url('timesheet/working/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('timesheet/working/' . $working->getRouteKey())) ->redirect(); } } /** * Remove multiple working. * * @param Model $working * * @return Response */ public function delete(WorkingRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('timesheet::working.name')])) ->status("success") ->code(202) ->url(guard_url('timesheet/working')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/timesheet/working')) ->redirect(); } } /** * Restore deleted workings. * * @param Model $working * * @return Response */ public function restore(WorkingRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('timesheet::working.name')])) ->status("success") ->code(202) ->url(guard_url('/timesheet/working')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/timesheet/working/')) ->redirect(); } } }