*/ use HasFactory, Notifiable; protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } public function projects(): BelongsToMany { return $this->belongsToMany(Project::class) ->withPivot('role') ->withTimestamps(); } public function ownedProjects(): BelongsToMany { return $this->projects()->wherePivot('role', 'owner'); } public function notificationPreferences(): HasMany { return $this->hasMany(NotificationPreference::class); } public function notificationPreferenceFor(Project $project): NotificationPreference { return $this->notificationPreferences() ->firstOrCreate( ['project_id' => $project->id], ['email_enabled' => true, 'database_enabled' => true, 'muted' => false], ); } public function tokens(): MorphMany { return $this->morphMany(PersonalAccessToken::class, 'tokenable'); } public function createToken(string $name, array $abilities = ['*'], ?\DateTimeInterface $expiresAt = null): PersonalAccessToken { $token = Str::random(64); return $this->tokens()->create([ 'name' => $name, 'token' => hash('sha256', $token), 'abilities' => $abilities, 'expires_at' => $expiresAt, ]); } }