47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Concerns\HasUuid;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Person extends Model
|
|
{
|
|
use HasUuid;
|
|
|
|
protected $table = 'persons';
|
|
|
|
protected $fillable = [
|
|
'uuid', 'name', 'avatar_color', 'avatar_path', 'user_id', 'mac', 'presence', 'presence_changed_at', 'last_seen_home_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'presence_changed_at' => 'datetime',
|
|
'last_seen_home_at' => 'datetime',
|
|
];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function isHome(): bool
|
|
{
|
|
return $this->presence === 'home';
|
|
}
|
|
|
|
public function avatarUrl(): ?string
|
|
{
|
|
return $this->avatar_path ? Storage::disk('public')->url($this->avatar_path) : null;
|
|
}
|
|
|
|
public function initials(): string
|
|
{
|
|
return Str::of($this->name)->explode(' ')->take(2)
|
|
->map(fn ($w) => Str::upper(Str::substr($w, 0, 1)))->implode('');
|
|
}
|
|
}
|