diff --git a/app/Http/Controllers/BewerbungController.php b/app/Http/Controllers/BewerbungController.php index 521442d..80aa2bf 100644 --- a/app/Http/Controllers/BewerbungController.php +++ b/app/Http/Controllers/BewerbungController.php @@ -2,36 +2,34 @@ namespace App\Http\Controllers; +use App\Models\Bewerbung; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; -use App\Models\Bewerbung; class BewerbungController extends Controller { public function index() { - $bewerbungen = Bewerbung::orderByDesc('created_at')->paginate(15); - return view('bewerbung_index', compact('bewerbungen')); + $bewerbungen = Bewerbung::latest()->paginate(15); + return view('bewerbung.index', compact('bewerbungen')); } public function create() { - return view('bewerbungc'); + 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'], - 'active' => ['nullable','boolean'], - 'time' => ['nullable','boolean'], - 'sdate' => ['nullable','date'], - 'edate' => ['nullable','date','after_or_equal:sdate'], - 'stime' => ['nullable','date_format:H:i'], - 'etime' => ['nullable','date_format:H:i'], + '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')) { @@ -41,42 +39,61 @@ class BewerbungController extends Controller $data['bedingungen_path'] = $request->file('bedingungen')->store('bewerbungen/bedingungen', 'public'); } - $data['active'] = (bool) $request->input('active', false); - $data['time'] = (bool) $request->input('time', false); + $data['active'] = $request->boolean('active'); + $data['time'] = $request->boolean('time'); - // Build datetime columns if provided - $start_at = null; - $end_at = null; + $bewerbung = Bewerbung::create($data); - if ($request->filled('sdate')) { - $start_at = $request->input('sdate'); - if ($request->filled('stime')) { - $start_at .= ' '.$request->input('stime').':00'; - } else { - $start_at .= ' 00:00:00'; - } - } + return redirect()->route('bewerbungen.show', $bewerbung)->with('success', 'Bewerbung erstellt.'); + } - if ($request->filled('edate')) { - $end_at = $request->input('edate'); - if ($request->filled('etime')) { - $end_at .= ' '.$request->input('etime').':00'; - } else { - $end_at .= ' 23:59:59'; - } - } + public function show(Bewerbung $bewerbung) + { + return view('bewerbung.show', compact('bewerbung')); + } - $bewerbung = Bewerbung::create([ - 'name' => $data['name'], - 'text' => $data['text'], - 'pic_path' => $data['pic_path'] ?? null, - 'bedingungen_path' => $data['bedingungen_path'] ?? null, - 'active' => $data['active'], - 'time' => $data['time'], - 'start_at' => $start_at, - 'end_at' => $end_at, + 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'], ]); - return redirect()->route('bewerbung.index')->with('success', 'Bewerbung gespeichert.'); + 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.'); } } diff --git a/app/Http/Controllers/bewerbung.php b/app/Http/Controllers/bewerbung.php deleted file mode 100644 index 58975cc..0000000 --- a/app/Http/Controllers/bewerbung.php +++ /dev/null @@ -1,39 +0,0 @@ -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'], - 'active' => ['sometimes','accepted'], - 'time' => ['sometimes','accepted'], - 'sdate' => ['nullable','date'], - 'edate' => ['nullable','date','after_or_equal:sdate'], - 'stime' => ['nullable','date_format:H:i'], - 'etime' => ['nullable','date_format:H:i'], - ]); - - 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'); - - // TODO: $bewerbung = Bewerbung::create($data); - - return redirect()->back()->with('success', 'Bewerbung gespeichert.'); - } -} diff --git a/app/Models/Bewerbung.php b/app/Models/Bewerbung.php index 988459a..f6905c0 100644 --- a/app/Models/Bewerbung.php +++ b/app/Models/Bewerbung.php @@ -12,14 +12,20 @@ class Bewerbung extends Model protected $table = 'bewerbungen'; protected $fillable = [ - 'name','text','pic_path','bedingungen_path','active','time', - 'start_at','end_at' + 'name', + 'text', + 'pic_path', + 'bedingungen_path', + 'active', + 'time', + 'start_at', + 'end_at', ]; protected $casts = [ 'active' => 'boolean', - 'time' => 'boolean', + 'time' => 'boolean', 'start_at' => 'datetime', - 'end_at' => 'datetime', + 'end_at' => 'datetime', ]; } diff --git a/database/migrations/2025_10_17_043346_bewerbung.php b/database/migrations/2025_10_17_043346_bewerbung.php index 92bbb93..b3225ed 100644 --- a/database/migrations/2025_10_17_043346_bewerbung.php +++ b/database/migrations/2025_10_17_043346_bewerbung.php @@ -10,31 +10,17 @@ return new class extends Migration { Schema::create('bewerbungen', function (Blueprint $table) { $table->id(); - - // Basisdaten $table->string('name', 255); - $table->text('text'); // Bewerbungstext ist i.d.R. länger als 255 - - // Dateien (optional) – Pfade in /storage/app/public/... - $table->string('pic_path', 2048)->nullable(); - $table->string('bedingungen_path', 2048)->nullable(); - - // Status & Zeitsteuerung - $table->boolean('active')->default(true)->index(); // "aktiv" -> lieber englisch/konsequent - $table->boolean('timed')->default(false)->index(); // ob zeitgesteuert - - // Zeitraum (optional, wenn timed = true) - $table->timestamp('start_at')->nullable()->index(); - $table->timestamp('end_at')->nullable()->index(); - + $table->text('text'); + $table->string('pic')->nullable(); // storage path + $table->string('pdf')->nullable(); // storage path + $table->boolean('active')->default(false); + $table->boolean('time')->default(false); + $table->timestamp('start_at')->nullable(); + $table->timestamp('end_at')->nullable(); $table->timestampsTz(); $table->softDeletesTz(); }); - - // OPTIONAL: DB-Check (MySQL 8+/Postgres) – nur wenn deine DB & Laravel-Version das unterstützen - // Schema::table('bewerbungen', function (Blueprint $table) { - // $table->check('(end_at IS NULL OR start_at IS NULL OR end_at >= start_at)'); - // }); } public function down(): void diff --git a/resources/views/bewerbung.blade.php b/resources/views/bewerbung.blade.php index 91c0800..adc2fe0 100644 --- a/resources/views/bewerbung.blade.php +++ b/resources/views/bewerbung.blade.php @@ -7,7 +7,7 @@
Muss noch variabel gefüllt werden
-