workspaces()->count() === 0) { Log::info('Creating new workspace for user with no workspaces', [ 'user_id' => $user->id, 'user_email' => $user->email, ]); $newWorkspace = Workspace::create([ 'name' => 'My Workspace', ]); $user->workspaces()->sync([ $newWorkspace->id => [ 'role' => 'admin', ], ], false); } } }