82 lines
1.8 KiB
PHP
82 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use App\Models\Transactions\Purchase;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @property int|null $asset_id
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'asset_id',
|
|
'price_tracking_enabled',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'price_tracking_enabled' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function asset(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Asset::class);
|
|
}
|
|
|
|
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)),
|
|
]);
|
|
}
|
|
|
|
public function hasCompletedOnboarding(): bool
|
|
{
|
|
return $this->hasPurchases() && $this->hasMilestones();
|
|
}
|
|
|
|
public function hasPurchases(): bool
|
|
{
|
|
return Purchase::totalShares() > 0;
|
|
}
|
|
|
|
public function hasMilestones(): bool
|
|
{
|
|
return Milestone::count() > 0;
|
|
}
|
|
}
|