key).'-base-template'; $suffix = 1; $candidate = $slug; while (ProjectTemplate::query()->where('slug', $candidate)->exists()) { $candidate = $slug.'-'.++$suffix; } return ProjectTemplate::query()->create([ 'project_id' => $project->id, 'source_project_id' => $project->id, 'name' => "{$project->name} base template", 'slug' => $candidate, 'is_published' => false, 'copy_areas' => $copyAreas, 'configuration_snapshot' => $this->duplicateProjectConfiguration->export($project, $copyAreas), ]); } }