authorizeAbility($request, 'security.view'); $organization = $this->organization($request); $owner = $this->ownerRef($request); $occupancy = Visit::owned($owner) ->where('organization_id', $organization->id) ->currentlyInside() ->with(['visitor', 'host']); $this->scopeToBranch($request, $occupancy); $occupancy = $occupancy->orderBy('checked_in_at')->get(); $expiredBadges = $occupancy->filter(fn (Visit $v) => $v->isBadgeExpired()); return view('frontdesk.security.index', [ 'occupancy' => $occupancy, 'expiredBadges' => $expiredBadges, 'organization' => $organization, 'canCheckout' => app(\App\Services\Frontdesk\FrontdeskPermissions::class) ->can($this->member($request), 'security.checkout'), ]); } public function evacuation(Request $request): View { $this->authorizeAbility($request, 'security.view'); $organization = $this->organization($request); $owner = $this->ownerRef($request); $occupancy = Visit::owned($owner) ->where('organization_id', $organization->id) ->currentlyInside() ->with(['visitor', 'host', 'branch']); $this->scopeToBranch($request, $occupancy); $occupancy = $occupancy->orderBy('checked_in_at')->get(); return view('frontdesk.security.evacuation', compact('occupancy', 'organization')); } public function evacuationBadges(Request $request, \App\Services\Frontdesk\BadgeRenderService $badges): View { $this->authorizeAbility($request, 'security.view'); $organization = $this->organization($request); $owner = $this->ownerRef($request); $visits = Visit::owned($owner) ->where('organization_id', $organization->id) ->currentlyInside() ->with(['visitor', 'host', 'organization']); $this->scopeToBranch($request, $visits); $visits = $visits->orderBy('checked_in_at')->get(); $rendered = $visits->map(fn (Visit $visit) => $badges->renderHtml($visit)); return view('frontdesk.security.evacuation-badges', compact('visits', 'rendered', 'organization')); } public function checkOut(Request $request, Visit $visit, VisitCheckOutService $checkOut): RedirectResponse { $this->authorizeAbility($request, 'security.checkout'); $this->authorizeOwner($request, $visit); $checkOut->checkOut($visit, $this->ownerRef($request)); return back()->with('success', 'Visitor checked out.'); } public function verifyForm(Request $request): View { $this->authorizeAbility($request, 'security.verify'); return view('frontdesk.security.verify', [ 'organization' => $this->organization($request), ]); } public function verify(Request $request): View { $this->authorizeAbility($request, 'security.verify'); $organization = $this->organization($request); $owner = $this->ownerRef($request); $validated = $request->validate([ 'lookup' => ['required', 'string', 'max:64'], ]); $lookup = trim($validated['lookup']); $visit = Visit::owned($owner) ->where('organization_id', $organization->id) ->where(function ($q) use ($lookup) { $q->where('badge_code', strtoupper($lookup)) ->orWhere('qr_token', $lookup); }) ->with(['visitor', 'host', 'branch']) ->latest('checked_in_at') ->first(); return view('frontdesk.security.verify', [ 'organization' => $organization, 'lookup' => $lookup, 'visit' => $visit, ]); } }