2025-07-10 15:24:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-05-01 23:27:38 +02:00
|
|
|
use Database\Factories\UserFactory;
|
2025-07-10 15:24:15 +02:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2026-05-02 17:10:00 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
2025-07-10 15:24:15 +02:00
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
2026-05-02 16:14:31 +02:00
|
|
|
use Illuminate\Support\Str;
|
2025-07-10 15:24:15 +02:00
|
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
|
{
|
2026-05-01 23:27:38 +02:00
|
|
|
/** @use HasFactory<UserFactory> */
|
2025-07-10 15:24:15 +02:00
|
|
|
use HasFactory, Notifiable;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'email',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'password',
|
|
|
|
|
'remember_token',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
|
'password' => 'hashed',
|
|
|
|
|
];
|
|
|
|
|
}
|
2025-08-01 00:36:05 +02:00
|
|
|
|
2026-05-02 17:10:00 +02:00
|
|
|
public function tracker(): HasOne
|
2025-08-01 00:36:05 +02:00
|
|
|
{
|
2026-05-02 17:10:00 +02:00
|
|
|
return $this->hasOne(Tracker::class);
|
2025-08-01 00:36:05 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-02 15:07:24 +02:00
|
|
|
public static function default(): self
|
|
|
|
|
{
|
2026-05-02 16:14:31 +02:00
|
|
|
return self::firstWhere('email', 'user@incr.local')
|
|
|
|
|
?? self::forceCreate([
|
|
|
|
|
'email' => 'user@incr.local',
|
|
|
|
|
'name' => 'Default User',
|
|
|
|
|
'password' => bcrypt(Str::random(32)),
|
|
|
|
|
]);
|
2026-05-02 15:07:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-01 00:36:05 +02:00
|
|
|
public function hasCompletedOnboarding(): bool
|
|
|
|
|
{
|
2026-05-02 17:10:00 +02:00
|
|
|
return $this->hasEntries() && $this->hasMilestones();
|
2025-08-01 00:36:05 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-02 17:10:00 +02:00
|
|
|
public function hasEntries(): bool
|
2025-08-01 00:36:05 +02:00
|
|
|
{
|
2026-05-02 17:10:00 +02:00
|
|
|
return (bool) $this->tracker?->entries()->exists();
|
2025-08-01 00:36:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hasMilestones(): bool
|
|
|
|
|
{
|
2026-05-02 17:10:00 +02:00
|
|
|
return (bool) $this->tracker?->milestones()->exists();
|
2025-08-01 00:36:05 +02:00
|
|
|
}
|
2025-07-10 15:24:15 +02:00
|
|
|
}
|