when($request->search, fn ($q, $term) => $q->where(fn ($q) => $q->where('name', 'like', "%{$term}%")->orWhere('employee_no', 'like', "%{$term}%"))) ->withCount(['issues as outstanding_items_count' => fn ($q) => $q->where('status', 'issued')]) ->orderBy('name')->paginate(15)->withQueryString(); return view('employees.index', compact('employees')); } public function store(Request $request) { Employee::create($request->validate([ 'employee_no' => ['required', 'string', 'max:50', 'unique:employees'], 'name' => ['required', 'string', 'max:150'], 'department' => ['required', 'string', 'max:100'], 'designation' => ['nullable', 'string', 'max:100'], 'joined_at' => ['nullable', 'date'], ])); return back()->with('success', 'Employee added successfully.'); } public function show(Employee $employee) { $employee->load(['issues.variant.item', 'handovers.items.issue.variant.item']); return view('employees.show', compact('employee')); } }