2026-03-29 22:24:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Actions\Workspace;
|
|
|
|
|
|
2026-03-31 03:40:18 +00:00
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-03-29 22:24:28 +00:00
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
|
|
|
|
|
class CreateWorkspace
|
|
|
|
|
{
|
|
|
|
|
public static function execute(User $user, array $data): Workspace
|
|
|
|
|
{
|
|
|
|
|
$workspace = Workspace::create([
|
2026-04-15 01:22:04 +00:00
|
|
|
'account_id' => $user->account_id,
|
2026-03-29 22:24:28 +00:00
|
|
|
'user_id' => $user->id,
|
|
|
|
|
...$data,
|
|
|
|
|
'timezone' => config('app.timezone', 'UTC'),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
|
2026-03-29 22:24:28 +00:00
|
|
|
$user->switchWorkspace($workspace);
|
|
|
|
|
|
|
|
|
|
return $workspace;
|
|
|
|
|
}
|
|
|
|
|
}
|