<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Services\AttendanceService; use App\Models\AttendanceRecord;
class AttendanceController extends Controller { public function index(){return view('attendance.index',['records'=>AttendanceRecord::where('user_id',request()->user()->id)->latest('work_date')->paginate(20)]);} public function punch(Request $request,AttendanceService $service){$data=$request->validate(['action'=>['required','in:check_in,check_out']]); try{$service->punch($request->user(),$data['action'],$request); return back()->with('success',str_replace('_',' ',ucfirst($data['action'])).' recorded successfully.');}catch(\RuntimeException $e){return back()->withErrors(['attendance'=>$e->getMessage()]);}} }
