|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Modules\HR\Http\Controllers; |
| 4 | + |
| 5 | +use App\Modules\HR\Models\TrainingSession; |
| 6 | +use Illuminate\Http\RedirectResponse; |
| 7 | +use Illuminate\Http\Request; |
| 8 | +use Inertia\Inertia; |
| 9 | +use Inertia\Response; |
| 10 | + |
| 11 | +class TrainingSessionController |
| 12 | +{ |
| 13 | + public function index(): Response |
| 14 | + { |
| 15 | + $sessions = TrainingSession::with('course') |
| 16 | + ->orderByDesc('scheduled_at') |
| 17 | + ->paginate(20); |
| 18 | + |
| 19 | + return Inertia::render('HR/TrainingSessions/Index', compact('sessions')); |
| 20 | + } |
| 21 | + |
| 22 | + public function create(): Response |
| 23 | + { |
| 24 | + return Inertia::render('HR/TrainingSessions/Create'); |
| 25 | + } |
| 26 | + |
| 27 | + public function store(Request $request): RedirectResponse |
| 28 | + { |
| 29 | + $data = $request->validate([ |
| 30 | + 'training_course_id' => 'required|exists:training_courses,id', |
| 31 | + 'title' => 'required|string|max:255', |
| 32 | + 'scheduled_at' => 'required|date', |
| 33 | + 'ends_at' => 'nullable|date|after:scheduled_at', |
| 34 | + 'description' => 'nullable|string', |
| 35 | + 'location' => 'nullable|string|max:255', |
| 36 | + 'delivery_mode' => 'nullable|string|in:in-person,online,hybrid', |
| 37 | + 'max_participants' => 'nullable|integer|min:1', |
| 38 | + 'facilitator_id' => 'nullable|exists:users,id', |
| 39 | + ]); |
| 40 | + |
| 41 | + $data['tenant_id'] = app('tenant')->id; |
| 42 | + $data['created_by'] = auth()->id(); |
| 43 | + |
| 44 | + TrainingSession::create($data); |
| 45 | + |
| 46 | + return redirect()->route('hr.training-sessions.index'); |
| 47 | + } |
| 48 | + |
| 49 | + public function show(TrainingSession $trainingSession): Response |
| 50 | + { |
| 51 | + $trainingSession->load('course', 'facilitator'); |
| 52 | + return Inertia::render('HR/TrainingSessions/Show', ['session' => $trainingSession]); |
| 53 | + } |
| 54 | + |
| 55 | + public function edit(TrainingSession $trainingSession): Response |
| 56 | + { |
| 57 | + return Inertia::render('HR/TrainingSessions/Edit', ['session' => $trainingSession]); |
| 58 | + } |
| 59 | + |
| 60 | + public function update(Request $request, TrainingSession $trainingSession): RedirectResponse |
| 61 | + { |
| 62 | + $data = $request->validate([ |
| 63 | + 'title' => 'required|string|max:255', |
| 64 | + 'scheduled_at' => 'required|date', |
| 65 | + 'ends_at' => 'nullable|date|after:scheduled_at', |
| 66 | + 'description' => 'nullable|string', |
| 67 | + 'location' => 'nullable|string|max:255', |
| 68 | + 'delivery_mode' => 'nullable|string|in:in-person,online,hybrid', |
| 69 | + 'max_participants' => 'nullable|integer|min:1', |
| 70 | + 'facilitator_id' => 'nullable|exists:users,id', |
| 71 | + ]); |
| 72 | + |
| 73 | + $trainingSession->update($data); |
| 74 | + |
| 75 | + return redirect()->route('hr.training-sessions.index'); |
| 76 | + } |
| 77 | + |
| 78 | + public function destroy(TrainingSession $trainingSession): RedirectResponse |
| 79 | + { |
| 80 | + $trainingSession->delete(); |
| 81 | + return redirect()->route('hr.training-sessions.index'); |
| 82 | + } |
| 83 | + |
| 84 | + public function start(TrainingSession $trainingSession): RedirectResponse |
| 85 | + { |
| 86 | + $trainingSession->start(); |
| 87 | + return redirect()->route('hr.training-sessions.index'); |
| 88 | + } |
| 89 | + |
| 90 | + public function complete(TrainingSession $trainingSession): RedirectResponse |
| 91 | + { |
| 92 | + $trainingSession->complete(); |
| 93 | + return redirect()->route('hr.training-sessions.index'); |
| 94 | + } |
| 95 | + |
| 96 | + public function cancel(TrainingSession $trainingSession): RedirectResponse |
| 97 | + { |
| 98 | + $trainingSession->cancel(); |
| 99 | + return redirect()->route('hr.training-sessions.index'); |
| 100 | + } |
| 101 | +} |
0 commit comments