Multi-tenant scoping via CorePHP tenant package. workspace_id column added to all three tables. Existing records backfilled to workspace 1 (Lethean CIC). workspaceContextRequired=false allows public API calls without workspace context. Commit #100. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
62 lines
1.3 KiB
PHP
62 lines
1.3 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
|
|
{
|
|
use \Core\Tenant\Concerns\BelongsToWorkspace;
|
|
|
|
protected bool $workspaceContextRequired = false;
|
|
|
|
protected $fillable = [
|
|
'claim_id',
|
|
'name',
|
|
'email',
|
|
'status',
|
|
'workspace_id',
|
|
];
|
|
|
|
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']);
|
|
}
|
|
}
|