<?php namespace App\Http\Controllers; use App\Models\{Expense,LeaveRequest,AttendanceRegularization,SalaryRevision,PayrollBatch,StipendBatch}; use App\Services\ApprovalService; use Illuminate\Http\Request; class ApprovalController extends Controller {private function resolve(string $type,int $id){$map=['expense'=>Expense::class,'leave'=>LeaveRequest::class,'regularization'=>AttendanceRegularization::class,'salary'=>SalaryRevision::class,'payroll'=>PayrollBatch::class,'stipend'=>StipendBatch::class];abort_unless(isset($map[$type]),404);return $map[$type]::findOrFail($id);} public function act(Request $r,string $type,int $id,ApprovalService $s){$d=$r->validate(['decision'=>'required|in:approved,rejected','comments'=>'nullable|string|max:2000']);try{$s->act($this->resolve($type,$id),$r->user(),$d['decision'],$d['comments']??null);return back()->with('success','Approval action recorded.');}catch(\RuntimeException $e){return back()->withErrors(['approval'=>$e->getMessage()]);}}}