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