Files
larablog/app/Models/User.php
T
goukiandCursor 64655ced1e
Build and Deploy / verify (push) Successful in 35s
Build and Deploy / deploy (push) Successful in 33s
feat: use xpier media library for uploads and markdown embeds
Store media:ID in article bodies instead of CDN URLs, and keep sablog attach tokens as a fallback.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 19:03:52 +00:00

87 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Support\LegacyPassword;
use Database\Factories\UserFactory;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements FilamentUser
{
/** @use HasFactory<UserFactory> */
use HasFactory, HasRoles, Notifiable;
public function canAccessPanel(Panel $panel): bool
{
return $this->hasRole(['admin', 'editor']);
}
protected $fillable = [
'name',
'username',
'email',
'password',
'password_legacy',
'url',
'login_count',
'login_ip',
'login_at',
'reg_ip',
'last_post_at',
];
protected $hidden = [
'password',
'password_legacy',
'remember_token',
];
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'login_count' => 'integer',
'login_at' => 'datetime',
'last_post_at' => 'datetime',
];
}
public function articles(): HasMany
{
return $this->hasMany(Article::class);
}
public function attemptLegacyPasswordUpgrade(string $plainPassword): bool
{
if (blank($this->password_legacy)) {
return false;
}
if (! LegacyPassword::verify($plainPassword, $this->password_legacy)) {
return false;
}
$this->forceFill([
'password' => Hash::make($plainPassword),
'password_legacy' => null,
])->save();
return true;
}
public function hasLegacyPassword(): bool
{
return filled($this->password_legacy);
}
}