2026-01-15 01:13:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
2026-01-20 19:53:54 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-01-17 17:44:37 +00:00
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-03-29 22:24:28 +00:00
|
|
|
use Database\Factories\WorkspaceInviteFactory;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
|
|
|
|
|
class WorkspaceInvite extends Model
|
|
|
|
|
{
|
2026-03-29 22:24:28 +00:00
|
|
|
/** @use HasFactory<WorkspaceInviteFactory> */
|
2026-01-20 19:53:54 +00:00
|
|
|
use HasFactory, HasUuids;
|
2026-01-15 01:13:44 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var list<string>
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'email',
|
|
|
|
|
'role',
|
2026-01-20 19:53:54 +00:00
|
|
|
'workspace_id',
|
2026-01-15 01:13:44 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-01-17 17:44:37 +00:00
|
|
|
'role' => Role::class,
|
2026-01-15 01:13:44 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function workspace(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Workspace::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function accept(User $user): void
|
|
|
|
|
{
|
|
|
|
|
$this->workspace->members()->attach($user->id, [
|
2026-01-20 19:53:54 +00:00
|
|
|
'role' => $this->role->value,
|
2026-01-15 01:13:44 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-01-20 19:53:54 +00:00
|
|
|
$this->delete();
|
2026-01-15 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
}
|