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