trypost/app/Models/User.php
Paulo Castellano afc4c7a80b feat(onboarding): add goal step after persona
After picking who they are, users now pick what they want to achieve with
TryPost. A multi-select goal step (12 options + an exclusive "just exploring"
and "something else") sits between the persona step and connect, mirroring the
persona screen's style.

The goals persist to a json column on users and are mirrored to PostHog on
identify (onboarding_goals array plus a boolean per goal), so campaigns can be
cross-tabbed against the intent they actually attracted. connect now requires
both a persona and at least one goal; persona store advances to the goal step.

Options are grounded in TryPost's real capabilities (publishing, AI content,
brand voice, automation via API/MCP, collaboration, analytics) and copy is
localized in en/es/pt-BR.
2026-06-25 20:49:04 -03:00

122 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Enums\Notification\Type as NotificationType;
use App\Enums\User\Persona;
use App\Models\Traits\HasMedia;
use App\Models\Traits\HasWorkspace;
use Database\Factories\UserFactory;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\Contracts\OAuthenticatable;
use Laravel\Passport\HasApiTokens;
class User extends Authenticatable implements MustVerifyEmail, OAuthenticatable
{
/** @use HasFactory<UserFactory> */
use HasApiTokens, HasFactory, HasMedia, HasUuids, HasWorkspace, Notifiable;
/**
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
'google_id',
'github_id',
'account_id',
'current_workspace_id',
'email_verified_at',
'utm_source',
'utm_medium',
'utm_campaign',
'utm_term',
'utm_content',
'registration_ip',
'persona',
'goals',
];
/**
* @var list<string>
*/
protected $hidden = [
'password',
'two_factor_secret',
'two_factor_recovery_codes',
'remember_token',
];
protected $appends = [
'has_photo',
'photo_url',
];
public function getHasPhotoAttribute(): bool
{
return $this->getFirstMedia('avatar') !== null;
}
public function getPhotoUrlAttribute(): ?string
{
return $this->getFirstMediaUrl('avatar');
}
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'two_factor_confirmed_at' => 'datetime',
'persona' => Persona::class,
'goals' => 'array',
];
}
public function notifications(): HasMany
{
return $this->hasMany(Notification::class);
}
public function notificationPreference(): HasOne
{
return $this->hasOne(NotificationPreference::class);
}
public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}
public function isAccountOwner(): bool
{
return $this->id === $this->account?->owner_id;
}
public function wantsEmailFor(NotificationType $type): bool
{
$preference = $this->notificationPreference;
if (! $preference) {
return true;
}
return match ($type) {
NotificationType::PostPublished => $preference->post_published,
NotificationType::PostFailed, NotificationType::PostPartiallyPublished => $preference->post_failed,
NotificationType::AccountDisconnected => $preference->account_disconnected,
NotificationType::MentionedInComment => $preference->mentioned_in_comment ?? true,
default => true,
};
}
}