attributes->get('api_user'); $businessId = is_array($apiUser) ? ($apiUser['business_id'] ?? null) : null; if (! $businessId && $request->user()) { $businessId = $request->user()->business_id; } if (! $businessId) { return null; } return Business::find($businessId); } protected function jsonSuccess(mixed $data = null, ?string $message = null, int $status = 200) { return response()->json([ 'success' => true, 'data' => $data, 'message' => $message, 'errors' => null, ], $status); } protected function jsonError(string $message, int $status = 400, mixed $errors = null) { return response()->json([ 'success' => false, 'data' => null, 'message' => $message, 'errors' => $errors, ], $status); } protected function ensureBusinessOwnership(Request $request, int $businessId): bool { $business = $this->resolveBusiness($request); return $business && (int) $business->id === $businessId; } }