incr/app/Models/User.php

65 lines
1.4 KiB
PHP
Raw Normal View History

2025-07-10 15:24:15 +02:00
<?php
namespace App\Models;
use Database\Factories\UserFactory;
2025-07-10 15:24:15 +02:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
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;
use Illuminate\Support\Str;
2025-07-10 15:24:15 +02:00
class User extends Authenticatable
{
/** @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
public function tracker(): HasOne
2025-08-01 00:36:05 +02:00
{
return $this->hasOne(Tracker::class);
2025-08-01 00:36:05 +02:00
}
public static function default(): self
{
return self::firstWhere('email', 'user@incr.local')
?? self::forceCreate([
'email' => 'user@incr.local',
'name' => 'Default User',
'password' => bcrypt(Str::random(32)),
]);
}
2025-08-01 00:36:05 +02:00
public function hasCompletedOnboarding(): bool
{
return $this->hasEntries() && $this->hasMilestones();
2025-08-01 00:36:05 +02:00
}
public function hasEntries(): bool
2025-08-01 00:36:05 +02:00
{
return (bool) $this->tracker?->entries()->exists();
2025-08-01 00:36:05 +02:00
}
public function hasMilestones(): bool
{
return (bool) $this->tracker?->milestones()->exists();
2025-08-01 00:36:05 +02:00
}
2025-07-10 15:24:15 +02:00
}