added method to convert projectname to valid dir name;

This commit is contained in:
Martin Folkerts 2025-03-26 20:42:37 +01:00
parent ddad4240d5
commit fb2e94c52a

View file

@ -6,6 +6,7 @@
use App\Models\ProjectEmailRecipient;
use App\Rules\HarvestFile;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Livewire\Component;
use Livewire\WithFileUploads;
@ -87,11 +88,19 @@ public function createProject()
])->validate();
$project = Project::create([
'name' => $this->formData['name'],
'download_path' => $this->formData['name']
'download_path' => $this->makeValidDirectoryName($this->formData['name'])
]);
return redirect()->route('project.show',[$project->name,'settings']);
}
private function makeValidDirectoryName($string)
{
return Str::of($string)
->replaceMatches('/[^a-zA-Z0-9_-]/', '_') // Replace invalid characters
->trim() // Remove leading/trailing spaces
->lower(); // Convert to lowercase
}
public function saveProject()
{
$this->resetErrorBag();