form = ManagerForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('project_managers.project_manager.modules'), 'project_manager', guard_url('project_manager')); } /** * Display a list of manager. * * @return Response */ public function index(ManagerRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Manager::pushScope(new RequestScope()) ->pushScope(new ManagerResourceScope()) ->simplePaginate($pageLimit); $data = new ManagersCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('project_manager::manager.names')) ->view('project_manager::manager.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display manager. * * @param Request $request * @param Model $manager * * @return Response */ public function show(ManagerRequest $request, Manager $model) { $form = $this->form; $modules = $this->modules; $data = new ManagerResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('project_manager::manager.name')) ->data(compact('data', 'form', 'modules')) ->view('project_manager::manager.show') ->output(); } /** * Show the form for creating a new manager. * * @param Request $request * * @return Response */ public function create(ManagerRequest $request, Manager $model) { $form = $this->form; $modules = $this->modules; $data = new ManagerResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('project_manager::manager.name')) ->view('project_manager::manager.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new manager. * * @param Request $request * * @return Response */ public function store(ManagerRequest $request, Manager $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new ManagerResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('project_manager::manager.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('project_manager/manager/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/project_manager/manager')) ->redirect(); } } /** * Show manager for editing. * * @param Request $request * @param Model $manager * * @return Response */ public function edit(ManagerRequest $request, Manager $model) { $form = $this->form; $modules = $this->modules; $data = new ManagerResource($model); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('project_manager::manager.name')) ->view('project_manager::manager.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the manager. * * @param Request $request * @param Model $manager * * @return Response */ public function update(ManagerRequest $request, Manager $model) { try { $attributes = $request->all(); $model = $model->update($attributes); $data = new ManagerResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('project_manager::manager.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('project_manager/manager/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('project_manager/manager/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the manager. * * @param Model $manager * * @return Response */ public function destroy(ManagerRequest $request, Manager $model) { try { $model->delete(); $data = new ManagerResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('project_manager::manager.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('project_manager/manager/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('project_manager/manager/' . $model->getRouteKey())) ->redirect(); } } }