diff --git a/app/Models/User.php b/app/Models/User.php index f51337f6..be1a6360 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -10,6 +10,7 @@ use JoelButcher\Socialstream\SetsProfilePhotoFromUrl; use Laravel\Fortify\TwoFactorAuthenticatable; use Laravel\Jetstream\HasProfilePhoto; +use Laravel\Jetstream\HasTeams; use Laravel\Sanctum\HasApiTokens; use Spatie\Permission\Traits\HasRoles; @@ -17,6 +18,7 @@ class User extends Authenticatable { use HasApiTokens; use HasConnectedAccounts; + use HasRoles; use HasFactory; use HasProfilePhoto { HasProfilePhoto::profilePhotoUrl as getPhotoUrl; @@ -24,7 +26,16 @@ class User extends Authenticatable use Notifiable; use SetsProfilePhotoFromUrl; use TwoFactorAuthenticatable; - use HasRoles; + use HasTeams; + + /** + * Get the teams the user belongs to. + */ + public function teams() + { + return $this->belongsToMany(Team::class, 'team_user')->withTimestamps(); + } + use Laravel\Jetstream\HasTeams; /** * The attributes that are mass assignable. @@ -79,4 +90,12 @@ public function profilePhotoUrl(): Attribute ? Attribute::get(fn () => $this->profile_photo_path) : $this->getPhotoUrl(); } + + /** + * Get the teams the user owns. + */ + public function ownedTeams() + { + return $this->hasMany(Team::class); + } }