From faa070f1f3db2572c16c846c99af1fe0fdeb03a0 Mon Sep 17 00:00:00 2001 From: Curtis Delicata Date: Sat, 20 Jul 2024 15:34:27 +0000 Subject: [PATCH] Upgrade composer and npm --- app/Models/User.php | 50 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 6d9ebbd8..4b5a2b9e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,8 +2,15 @@ namespace App\Models; +use Filament\Models\Contracts\FilamentUser; +use Filament\Models\Contracts\HasDefaultTenant; +use Filament\Models\Contracts\HasTenants; +use Filament\Panel; use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use JoelButcher\Socialstream\HasConnectedAccounts; @@ -14,7 +21,7 @@ use Laravel\Sanctum\HasApiTokens; use Spatie\Permission\Traits\HasRoles; -class User extends Authenticatable +class User extends Authenticatable implements HasDefaultTenant, HasTenants, FilamentUser { use HasApiTokens; use HasConnectedAccounts; @@ -28,14 +35,6 @@ class User extends Authenticatable use TwoFactorAuthenticatable; use HasTeams; - /** - * Get the teams the user belongs to. - */ - public function teams() - { - return $this->belongsToMany(Team::class, 'team_user')->withTimestamps(); - } - /** * The attributes that are mass assignable. * @@ -91,10 +90,37 @@ public function profilePhotoUrl(): Attribute } /** - * Get the teams the user owns. + * @return array | Collection */ - public function ownedTeams() + public function getTenants(Panel $panel): array|Collection + { + return $this->ownedTeams; + } + + public function canAccessTenant(Model $tenant): bool + { + return true; //$this->ownedTeams->contains($tenant); + } + + public function canAccessPanel(Panel $panel): bool + { + // return $this->hasVerifiedEmail(); + return true; + } + + public function canAccessFilament(): bool + { + // return $this->hasVerifiedEmail(); + return true; + } + + public function getDefaultTenant(Panel $panel): ?Model + { + return $this->latestTeam; + } + + public function latestTeam(): BelongsTo { - return $this->hasMany(Team::class); + return $this->belongsTo(Team::class, 'current_team_id'); } }