|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Modules\HR\Http\Controllers; |
| 4 | + |
| 5 | +use App\Http\Controllers\Controller; |
| 6 | +use App\Modules\HR\Models\EmployeeSkill; |
| 7 | +use Illuminate\Http\RedirectResponse; |
| 8 | +use Illuminate\Http\Request; |
| 9 | +use Inertia\Inertia; |
| 10 | +use Inertia\Response; |
| 11 | + |
| 12 | +class EmployeeSkillController extends Controller |
| 13 | +{ |
| 14 | + public function index(Request $request): Response |
| 15 | + { |
| 16 | + $this->authorize('viewAny', EmployeeSkill::class); |
| 17 | + |
| 18 | + $query = EmployeeSkill::with(['employee', 'definition']); |
| 19 | + |
| 20 | + if ($request->filled('employee_id')) { |
| 21 | + $query->where('employee_id', $request->employee_id); |
| 22 | + } |
| 23 | + |
| 24 | + $skills = $query->latest()->paginate(20); |
| 25 | + |
| 26 | + return Inertia::render('HR/EmployeeSkills/Index', compact('skills')); |
| 27 | + } |
| 28 | + |
| 29 | + public function store(Request $request): RedirectResponse |
| 30 | + { |
| 31 | + $this->authorize('create', EmployeeSkill::class); |
| 32 | + |
| 33 | + $data = $request->validate([ |
| 34 | + 'employee_id' => 'required|exists:employees,id', |
| 35 | + 'skill_name' => 'required|string|max:255', |
| 36 | + 'skill_definition_id' => 'nullable|exists:skill_definitions,id', |
| 37 | + 'proficiency_level' => 'required|integer|min:1|max:5', |
| 38 | + 'acquired_date' => 'nullable|date', |
| 39 | + 'notes' => 'nullable|string', |
| 40 | + ]); |
| 41 | + |
| 42 | + EmployeeSkill::create([ |
| 43 | + 'tenant_id' => auth()->user()->tenant_id, |
| 44 | + ...$data, |
| 45 | + ]); |
| 46 | + |
| 47 | + return redirect()->back()->with('success', 'Skill added.'); |
| 48 | + } |
| 49 | + |
| 50 | + public function show(EmployeeSkill $employeeSkill): Response |
| 51 | + { |
| 52 | + $this->authorize('view', $employeeSkill); |
| 53 | + |
| 54 | + $employeeSkill->load(['employee', 'definition']); |
| 55 | + |
| 56 | + return Inertia::render('HR/EmployeeSkills/Show', compact('employeeSkill')); |
| 57 | + } |
| 58 | + |
| 59 | + public function verify(EmployeeSkill $employeeSkill): RedirectResponse |
| 60 | + { |
| 61 | + $this->authorize('update', $employeeSkill); |
| 62 | + |
| 63 | + $employeeSkill->verify(auth()->id()); |
| 64 | + |
| 65 | + return redirect()->back()->with('success', 'Skill verified.'); |
| 66 | + } |
| 67 | + |
| 68 | + public function destroy(EmployeeSkill $employeeSkill): RedirectResponse |
| 69 | + { |
| 70 | + $this->authorize('delete', $employeeSkill); |
| 71 | + |
| 72 | + $employeeSkill->delete(); |
| 73 | + |
| 74 | + return redirect()->back()->with('success', 'Skill deleted.'); |
| 75 | + } |
| 76 | +} |
0 commit comments