diff --git a/app/Http/Controllers/BandApplicationController.php b/app/Http/Controllers/BandApplicationController.php new file mode 100644 index 0000000..374294a --- /dev/null +++ b/app/Http/Controllers/BandApplicationController.php @@ -0,0 +1,95 @@ +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.'); + } +} diff --git a/app/Models/Band.php b/app/Models/Band.php new file mode 100644 index 0000000..9a0c44d --- /dev/null +++ b/app/Models/Band.php @@ -0,0 +1,30 @@ +hasMany(BandApplication::class); + } +} diff --git a/app/Models/BandApplication.php b/app/Models/BandApplication.php new file mode 100644 index 0000000..55f91d5 --- /dev/null +++ b/app/Models/BandApplication.php @@ -0,0 +1,36 @@ + 'boolean', + 'created_at' => 'datetime', + 'updated_at' => 'datetime', + ]; + + public function band() + { + return $this->belongsTo(Band::class); + } + + public function bewerbung() + { + return $this->belongsTo(Bewerbung::class); + } +} diff --git a/app/Models/Bewerbung.php b/app/Models/Bewerbung.php index f6905c0..3dcbf30 100644 --- a/app/Models/Bewerbung.php +++ b/app/Models/Bewerbung.php @@ -28,4 +28,15 @@ class Bewerbung extends Model 'start_at' => 'datetime', 'end_at' => 'datetime', ]; + // app/Models/Bewerbung.php +public function applications() +{ + return $this->hasMany(\App\Models\BandApplication::class, 'bewerbung_id'); } + +public function getRouteKeyName() +{ + return 'slug'; +} +} + diff --git a/database/migrations/2025_10_24_000000_create_bewerbungen_table.php b/database/migrations/2025_10_24_000000_create_bewerbungen_table.php new file mode 100644 index 0000000..3c31dc3 --- /dev/null +++ b/database/migrations/2025_10_24_000000_create_bewerbungen_table.php @@ -0,0 +1,30 @@ +id(); + $table->string('name'); + $table->string('slug')->unique(); + $table->text('text')->nullable(); + $table->boolean('active')->default(false); + $table->boolean('time')->default(false); + $table->string('pdf_path')->nullable(); + $table->string('pic_path')->nullable(); + $table->string('bedingungen_path')->nullable(); + $table->timestamp('start_at')->nullable(); + $table->timestamp('end_at')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('bewerbungen'); + } +}; diff --git a/database/migrations/2025_10_24_000010_create_bands_table.php b/database/migrations/2025_10_24_000010_create_bands_table.php new file mode 100644 index 0000000..e4db49a --- /dev/null +++ b/database/migrations/2025_10_24_000010_create_bands_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->string('email')->unique(); + $table->string('phone')->nullable(); + $table->string('city')->nullable(); + $table->string('website')->nullable(); + $table->string('spotify')->nullable(); + $table->string('instagram')->nullable(); + $table->string('youtube')->nullable(); + $table->text('about')->nullable(); + $table->string('tech_rider_path')->nullable(); + $table->string('stage_plan_path')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('bands'); + } +}; diff --git a/database/migrations/2025_10_24_000020_create_band_applications_table.php b/database/migrations/2025_10_24_000020_create_band_applications_table.php new file mode 100644 index 0000000..d475000 --- /dev/null +++ b/database/migrations/2025_10_24_000020_create_band_applications_table.php @@ -0,0 +1,27 @@ +id(); + $table->foreignId('band_id')->constrained('bands')->cascadeOnDelete(); + $table->foreignId('bewerbung_id')->constrained('bewerbungen')->cascadeOnDelete(); + $table->string('status')->default('submitted'); + $table->text('message')->nullable(); + $table->string('demo_link')->nullable(); + $table->boolean('privacy_ok')->default(false); + $table->timestamps(); + $table->unique(['band_id','bewerbung_id']); + }); + } + + public function down(): void + { + Schema::dropIfExists('band_applications'); + } +}; diff --git a/routes/web.php b/routes/web.php index 7a0142e..908a7bc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -18,9 +18,7 @@ Route::get('/', function () { Route::get('info', function() { return view('info'); }); -Route::get('bewerbung', function() { - return view('bewerbung'); -}); +//Route::get('bewerbung', function() { return view('bewerbung');}); Route::get('start', function() { return view('start'); }); @@ -33,5 +31,5 @@ Route::get('kontakt', function() { // Bewerbung CRUD -Route::resource('bewerbungen', BewerbungController::class) -->parameters(['bewerbungen' => 'bewerbung']); // ← erzwingt {bewerbung} +//Route::resource('bewerbungen', BewerbungController::class) +//->parameters(['bewerbungen' => 'bewerbung']); // ← erzwingt {bewerbung}