Bewerbungsformular update

This commit is contained in:
Nils Bonorden committed 2025-10-24 15:05:16 +02:00
1 parent 20558065ad
commit bdb62a6ce2
13 files changed
+646 -171

No files matched your search

@@ -0,0 +1,58 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\BandApplication;
use App\Models\Bewerbung;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;
class BandApplicationAdminController extends Controller
{
// Einzelansicht einer Bewerbung
public function show(BandApplication $application)
{
$application->load(['band','bewerbung']);
return view('admin.applications.show', compact('application'));
}
// Status ändern (submitted, in_review, accepted, rejected)
public function updateStatus(Request $request, BandApplication $application)
{
$data = $request->validate([
'status' => ['required','in:submitted,in_review,accepted,rejected'],
]);
$application->update($data);
return back()->with('success', 'Status aktualisiert.');
}
// Optional: CSV-Export aller Bewerbungen einer Runde
// public function exportCsv(Bewerbung $bewerbung): StreamedResponse
// {
// $filename = 'applications_' . $bewerbung->slug . '.csv';
// $headers = [
// 'Content-Type' => 'text/csv',
// 'Content-Disposition' => 'attachment; filename="'.$filename.'"',
// ];
// $callback = function() use ($bewerbung) {
// $handle = fopen('php://output', 'w');
// fputcsv($handle, ['ID','Band','Email','Status','Datum','Demo','Nachricht']);
// foreach ($bewerbung->applications()->with('band')->cursor() as $app) {
// fputcsv($handle, [
// $app->id,
// optional($app->band)->name,
// optional($app->band)->email,
// $app->status,
// $app->created_at,
// $app->demo_link,
// preg_replace("/\r|\n/", " ", (string)$app->message),
// ]);
// }
// fclose($handle);
// };
// return response()->stream($callback, 200, $headers);
// }
}
@@ -0,0 +1,33 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Bewerbung;
use Illuminate\Http\Request;
class BewerbungAdminController extends Controller
{
// Übersicht aller Runden
public function index(Request $request)
{
$bewerbungen = Bewerbung::query()
->withCount('applications')
->orderByDesc('start_at')
->orderBy('name')
->paginate(20);
return view('admin.bewerbungen.index', compact('bewerbungen'));
}
// Detailseite einer Runde mit Bewerbungs-Tabelle
public function show(Bewerbung $bewerbung)
{
$applications = $bewerbung->applications()
->with('band')
->latest()
->paginate(25);
return view('admin.bewerbungen.show', compact('bewerbung','applications'));
}
}
+9 -80
View File
@@ -4,96 +4,25 @@ namespace App\Http\Controllers;
use App\Models\Bewerbung;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class BewerbungController extends Controller
{
public function index()
{
$bewerbungen = Bewerbung::latest()->paginate(15);
$bewerbungen = Bewerbung::query()
->where('active', true)
->orderByDesc('start_at')
->get();
return view('bewerbung.index', compact('bewerbungen'));
}
public function create()
{
return view('bewerbung.create');
}
public function store(Request $request)
{
$data = $request->validate([
'name' => ['required','string','max:255'],
'text' => ['required','string','max:5000'],
'pic' => ['nullable','image','mimes:jpg,jpeg,png','max:4096'],
'bedingungen' => ['nullable','file','mimetypes:application/pdf','max:8192'],
'time' => ['nullable'],
'active' => ['nullable'],
'start_at' => ['nullable','date'],
'end_at' => ['nullable','date','after_or_equal:start_at'],
]);
if ($request->hasFile('pic')) {
$data['pic_path'] = $request->file('pic')->store('bewerbungen/pics', 'public');
}
if ($request->hasFile('bedingungen')) {
$data['bedingungen_path'] = $request->file('bedingungen')->store('bewerbungen/bedingungen', 'public');
}
$data['active'] = $request->boolean('active');
$data['time'] = $request->boolean('time');
$bewerbung = Bewerbung::create($data);
return redirect()->route('bewerbungen.show', $bewerbung)->with('success', 'Bewerbung erstellt.');
}
public function show(Bewerbung $bewerbung)
{
if (!$bewerbung->active) abort(404);
if ($bewerbung->start_at && $bewerbung->start_at->isFuture()) abort(404);
if ($bewerbung->end_at && $bewerbung->end_at->isPast()) abort(404);
return view('bewerbung.show', compact('bewerbung'));
}
public function edit(Bewerbung $bewerbung)
{
return view('bewerbung.edit', compact('bewerbung'));
}
public function update(Request $request, Bewerbung $bewerbung)
{
$data = $request->validate([
'name' => ['required','string','max:255'],
'text' => ['required','string','max:5000'],
'pic' => ['nullable','image','mimes:jpg,jpeg,png','max:4096'],
'bedingungen' => ['nullable','file','mimetypes:application/pdf','max:8192'],
'time' => ['nullable'],
'active' => ['nullable'],
'start_at' => ['nullable','date'],
'end_at' => ['nullable','date','after_or_equal:start_at'],
]);
if ($request->hasFile('pic')) {
if ($bewerbung->pic_path) Storage::disk('public')->delete($bewerbung->pic_path);
$data['pic_path'] = $request->file('pic')->store('bewerbungen/pics', 'public');
}
if ($request->hasFile('bedingungen')) {
if ($bewerbung->bedingungen_path) Storage::disk('public')->delete($bewerbung->bedingungen_path);
$data['bedingungen_path'] = $request->file('bedingungen')->store('bewerbungen/bedingungen', 'public');
}
$data['active'] = $request->boolean('active');
$data['time'] = $request->boolean('time');
$bewerbung->update($data);
return redirect()->route('bewerbungen.show', $bewerbung)->with('success', 'Bewerbung aktualisiert.');
}
public function destroy(Bewerbung $bewerbung)
{
if ($bewerbung->pic_path) Storage::disk('public')->delete($bewerbung->pic_path);
if ($bewerbung->bedingungen_path) Storage::disk('public')->delete($bewerbung->bedingungen_path);
$bewerbung->delete();
return redirect()->route('bewerbungen.index')->with('success', 'Bewerbung gelöscht.');
}
}