Deploy Ladill QR Plus / deploy (push) Successful in 28s
Full control center for ticketed events, contributions, attendees, badges, and programmes — not a QR utility clone. Includes SSO shell, import command, and platform cutover runbook. Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
2.3 KiB
PHP
86 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Collection;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
/**
|
|
* Thin local mirror of the platform identity (auth.ladill.com owns users).
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasApiTokens, HasFactory, Notifiable;
|
|
|
|
protected $fillable = ['public_id', 'name', 'email', 'avatar_url', 'password'];
|
|
|
|
protected $hidden = ['password', 'remember_token'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['email_verified_at' => 'datetime', 'password' => 'hashed'];
|
|
}
|
|
|
|
public function memberships(): HasMany
|
|
{
|
|
return $this->hasMany(QrTeamMember::class, 'user_id')
|
|
->where('status', QrTeamMember::STATUS_ACTIVE);
|
|
}
|
|
|
|
public function canAccessAccount(int $accountId): bool
|
|
{
|
|
return $accountId === $this->id
|
|
|| $this->memberships()->where('account_id', $accountId)->exists();
|
|
}
|
|
|
|
/** @return Collection<int, User> */
|
|
public function accessibleAccounts(): Collection
|
|
{
|
|
$ids = $this->memberships()->pluck('account_id')->all();
|
|
|
|
return collect([$this])->merge(self::whereIn('id', $ids)->get())->unique('id')->values();
|
|
}
|
|
|
|
public function qrWallet(): HasOne
|
|
{
|
|
return $this->hasOne(QrWallet::class);
|
|
}
|
|
|
|
public function qrCodes(): HasMany
|
|
{
|
|
return $this->hasMany(QrCode::class);
|
|
}
|
|
|
|
public function qrSetting(): HasOne
|
|
{
|
|
return $this->hasOne(QrSetting::class);
|
|
}
|
|
|
|
public function getOrCreateQrSetting(): QrSetting
|
|
{
|
|
return $this->qrSetting()->firstOrCreate([]);
|
|
}
|
|
|
|
public function getOrCreateQrWallet(): QrWallet
|
|
{
|
|
return $this->qrWallet()->firstOrCreate(
|
|
[],
|
|
['credit_balance' => 0, 'qr_codes_total' => 0, 'scans_total' => 0, 'status' => QrWallet::STATUS_ACTIVE],
|
|
);
|
|
}
|
|
|
|
public function avatarUrl(): ?string
|
|
{
|
|
$url = trim((string) $this->avatar_url);
|
|
|
|
return $url !== '' ? $url : null;
|
|
}
|
|
}
|