lthn.io/app/Mod/Names/Models/NameClaim.php
Claude ca11c4ccee
refactor: extract Actions for CheckAvailability, SubmitClaim, RegisterName
CorePHP Actions pattern — single-purpose classes with static ::run().
Controller methods now delegate to Actions. Each Action validates,
executes, and returns typed results. Enables reuse from commands,
jobs, and tests without going through HTTP.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 11:24:27 +01:00

57 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Mod\Names\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Pre-registration name claim.
*
* $claim = NameClaim::create(['name' => 'mybrand', 'email' => 'me@example.com']);
* $pending = NameClaim::pending()->get();
* $claim->approve();
*/
class NameClaim extends Model
{
protected $fillable = [
'claim_id',
'name',
'email',
'status',
];
protected $attributes = [
'status' => 'pending',
];
protected static function booted(): void
{
static::creating(function (self $claim) {
if (empty($claim->claim_id)) {
$claim->claim_id = bin2hex(random_bytes(6));
}
});
}
public function scopePending($query)
{
return $query->where('status', 'pending');
}
public function scopeApproved($query)
{
return $query->where('status', 'approved');
}
public function approve(): void
{
$this->update(['status' => 'approved']);
}
public function reject(): void
{
$this->update(['status' => 'rejected']);
}
}