/** * Create a new team for the given user and data. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param array $data * @return \Laravel\Spark\Teams\Team */ public function create($user, array $data) { $class = Spark::model('teams', Team::class); $team = new $class(['name' => $data['name']]); $team->owner_id = $user->id; $team->save(); $team = $user->teams()->attach($team, ['role' => 'owner']); return $team; }
/** * Get the team that owns the invitation. */ public function team() { return $this->belongsTo(Spark::model('teams', Team::class), 'team_id'); }
/** * Get all of the teams that the user belongs to. */ public function teams() { return $this->belongsToMany(Spark::model('teams', Team::class), 'user_teams', 'user_id', 'team_id')->withPivot(['role'])->orderBy('name', 'asc'); }