/** * Updates a project namespace. * * @param \Gitamin\Models\Owner $namespace * * @return \Illuminate\Http\RedirectResponse */ public function updateAction($path) { $groupData = Request::get('group'); $group = Owner::where('path', '=', $path)->first(); try { $groupData['owner'] = $group; $groupData['user_id'] = Auth::user()->id; $group = $this->dispatchFromArray(UpdateOwnerCommand::class, $groupData); } catch (ValidationException $e) { return Redirect::route('groups.group_edit', ['owner' => $group->path])->withInput(Request::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('groups.group_edit', ['owner' => $group->path])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('gitamin.groups.edit.success'))); }
/** * Overrides the models boot method. */ public static function boot() { parent::boot(); self::creating(function ($user) { $ownerExists = Owner::where('path', '=', $user->username)->exists(); $userExists = User::where('username', '=', $user->username)->orWhere('email', '=', $user->email)->exists(); if ($ownerExists === true || $userExists === true) { throw new UserAlreadyTakenException('Username or email has already been taken.'); } if (!$user->api_key) { $user->api_key = self::generateApiKey(); } }); }
/** * Register model bindings. * * @return void */ protected function registerBindings() { $this->app->router->model('owner', Owner::class, function ($slug) { return Owner::where('slug', $slug)->firstOrFail(); }); $this->app->router->bind('project', function ($slug, $route) { $owner = $route->getParameter('owner'); return Project::where(['owner_id' => $owner->id, 'slug' => $slug])->firstOrFail(); }); $this->app->router->bind('issue', function ($iid, $route) { $project = $route->getParameter('project'); return Issue::where(['project_id' => $project->id, 'iid' => $iid])->firstOrFail(); }); }
/** * Show the form or adding a new resource. * * return \Illuminate\Http\Response */ public function newAction() { return View::make('projects.new')->withPageTitle(trans('dashboard.projects.new.title') . ' - ' . trans('dashboard.dashboard'))->withGroupId('')->withOwners(Owner::where('user_id', '=', Auth::user()->id)->get()); }