From 1b1130cb2bb0e0fe7b7f9bef7c8d3080e3387de8 Mon Sep 17 00:00:00 2001 From: Curtis Delicata Date: Sat, 29 Jun 2024 15:20:52 +0000 Subject: [PATCH] Configure Jetstream classes in providers and separate panels into Admin and App --- app/Models/User.php | 71 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 0ee52f6..be1a636 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,16 +2,40 @@ namespace App\Models; -// use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use JoelButcher\Socialstream\HasConnectedAccounts; +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; class User extends Authenticatable { - use HasApiTokens, HasFactory, Notifiable, HasRoles; + use HasApiTokens; + use HasConnectedAccounts; + use HasRoles; + use HasFactory; + use HasProfilePhoto { + HasProfilePhoto::profilePhotoUrl as getPhotoUrl; + } + use Notifiable; + use SetsProfilePhotoFromUrl; + use TwoFactorAuthenticatable; + 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. @@ -25,22 +49,53 @@ class User extends Authenticatable ]; /** - * The attributes that should be hidden for serialization. + * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', + 'two_factor_recovery_codes', + 'two_factor_secret', ]; /** - * The attributes that should be cast. + * The accessors to append to the model's array form. * - * @var array + * @var array */ - protected $casts = [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', + protected $appends = [ + 'profile_photo_url', ]; + + /** + * Get the attributes that should be cast. + * + * @return array + */ + protected function casts(): array + { + return [ + 'email_verified_at' => 'datetime', + ]; + } + + /** + * Get the URL to the user's profile photo. + */ + public function profilePhotoUrl(): Attribute + { + return filter_var($this->profile_photo_path, FILTER_VALIDATE_URL) + ? Attribute::get(fn () => $this->profile_photo_path) + : $this->getPhotoUrl(); + } + + /** + * Get the teams the user owns. + */ + public function ownedTeams() + { + return $this->hasMany(Team::class); + } }