Fixes mit chtgpt

This commit is contained in:
Nils Bonorden committed 2025-10-17 10:00:01 +02:00
1 parent fcae679714
commit 3db040e243
4 files changed
+112 -13

No files matched your search

@@ -0,0 +1,82 @@
<?php
namespace App\Http\Controllers;
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'));
}
public function create()
{
return view('bewerbungc');
}
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'],
]);
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'] = (bool) $request->input('active', false);
$data['time'] = (bool) $request->input('time', false);
// Build datetime columns if provided
$start_at = null;
$end_at = null;
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';
}
}
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';
}
}
$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,
]);
return redirect()->route('bewerbung.index')->with('success', 'Bewerbung gespeichert.');
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Bewerbung extends Model
{
use HasFactory;
protected $table = 'bewerbungen';
protected $fillable = [
'name','text','pic_path','bedingungen_path','active','time',
'start_at','end_at'
];
protected $casts = [
'active' => 'boolean',
'time' => 'boolean',
'start_at' => 'datetime',
'end_at' => 'datetime',
];
}