56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Mod\Names\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Activity log for name operations.
|
||
|
|
*
|
||
|
|
* NameActivity::log('mybrand', 'registered', ['address' => '...']);
|
||
|
|
* NameActivity::log('mybrand', 'dns_updated', ['records' => [...]]);
|
||
|
|
* $recent = NameActivity::forName('mybrand')->latest()->get();
|
||
|
|
*/
|
||
|
|
class NameActivity extends Model
|
||
|
|
{
|
||
|
|
public $timestamps = false;
|
||
|
|
|
||
|
|
protected $table = 'name_activity';
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'name',
|
||
|
|
'event',
|
||
|
|
'properties',
|
||
|
|
'ip_hash',
|
||
|
|
'created_at',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'properties' => 'array',
|
||
|
|
'created_at' => 'datetime',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function scopeForName($query, string $name)
|
||
|
|
{
|
||
|
|
return $query->where('name', $name);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Log a name activity event.
|
||
|
|
*
|
||
|
|
* NameActivity::log('mybrand', 'claimed', ['email' => 'me@example.com']);
|
||
|
|
*/
|
||
|
|
public static function log(string $name, string $event, array $properties = [], ?string $ip = null): self
|
||
|
|
{
|
||
|
|
return static::create([
|
||
|
|
'name' => $name,
|
||
|
|
'event' => $event,
|
||
|
|
'properties' => $properties,
|
||
|
|
'ip_hash' => $ip ? hash('sha256', $ip) : null,
|
||
|
|
'created_at' => now(),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|