require(); $staff = $request->user()->staffProfiles() ->where('businessId', $business->id) ->with('role.permissions') ->first(); abort_unless($staff, 403); $isOwner = $staff->hasPermission(Permission::ViewAllStaffAppointments); $today = Carbon::now($business->timezone); $appointments = Appointment::query() ->where('businessId', $business->id) ->when(! $isOwner, fn ($query) => $query->where('staffId', $staff->id)) ->whereBetween('startAt', [$today->copy()->startOfDay()->utc(), $today->copy()->endOfDay()->utc()]) ->with(['customer', 'staff.user', 'services.service']) ->orderBy('startAt') ->get(); return view('staff.dashboard', compact('business', 'staff', 'appointments', 'isOwner')); } }