34 lines
811 B
PHP
34 lines
811 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Device extends Model {
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id', 'name', 'token', 'hardware',
|
|
'firmware_version', 'last_seen_at', 'settings',
|
|
];
|
|
|
|
protected $casts = [
|
|
'last_seen_at' => 'datetime',
|
|
'settings' => 'array',
|
|
];
|
|
|
|
public function user(): BelongsTo { return $this->belongsTo(User::class); }
|
|
|
|
/** Genera un token nuevo seguro */
|
|
public static function makeToken(): string {
|
|
return Str::random(48);
|
|
}
|
|
|
|
public function touchSeen(): void {
|
|
$this->update(['last_seen_at' => now()]);
|
|
}
|
|
}
|