validate([ // Band-Stammdaten 'band.name' => ['required','string','max:255'], 'band.email' => ['required','email','max:255'], 'band.phone' => ['nullable','string','max:100'], 'band.city' => ['nullable','string','max:255'], 'band.website' => ['nullable','url','max:255'], 'band.spotify' => ['nullable','url','max:255'], 'band.instagram' => ['nullable','url','max:255'], 'band.youtube' => ['nullable','url','max:255'], 'band.about' => ['nullable','string','max:5000'], // Dateien optional 'band.tech_rider' => ['nullable','file','mimes:pdf','max:8192'], 'band.stage_plan' => ['nullable','file','mimes:pdf','max:8192'], // Bewerbung 'message' => ['nullable','string','max:5000'], 'demo_link' => ['nullable','url','max:255'], 'privacy_ok' => ['accepted'], // muss angehakt sein ]); $application = DB::transaction(function() use ($data, $request, $bewerbung) { // 1) Band per E-Mail finden/neu anlegen $band = Band::firstOrNew(['email' => $data['band']['email']]); $band->fill([ 'name' => $data['band']['name'], 'phone' => $data['band']['phone'] ?? null, 'city' => $data['band']['city'] ?? null, 'website' => $data['band']['website'] ?? null, 'spotify' => $data['band']['spotify'] ?? null, 'instagram' => $data['band']['instagram'] ?? null, 'youtube' => $data['band']['youtube'] ?? null, 'about' => $data['band']['about'] ?? null, ]); if ($request->hasFile('band.tech_rider')) { $band->tech_rider_path = $request->file('band.tech_rider')->store('bands/tech', 'public'); } if ($request->hasFile('band.stage_plan')) { $band->stage_plan_path = $request->file('band.stage_plan')->store('bands/stage', 'public'); } $band->save(); // 2) Bewerbungs-Duplikate verhindern $existing = BandApplication::where('band_id', $band->id) ->where('bewerbung_id', $bewerbung->id) ->first(); if ($existing) { // Optional: Nachricht/Demolink aktualisieren $existing->update([ 'message' => $data['message'] ?? $existing->message, 'demo_link' => $data['demo_link'] ?? $existing->demo_link, ]); return $existing; } // 3) Bewerbung anlegen return BandApplication::create([ 'band_id' => $band->id, 'bewerbung_id' => $bewerbung->id, 'status' => 'submitted', 'message' => $data['message'] ?? null, 'demo_link' => $data['demo_link'] ?? null, 'privacy_ok' => true, ]); }); return redirect() ->route('bewerbung.show', $bewerbung) // oder ['bewerbung' => $bewerbung->slug] ->with('success', 'Danke! Eure Bewerbung ist eingegangen.'); } }