header('X-Api-Key'); $apiSecret = $request->header('X-Api-Secret'); $ipAddress = $request->ip(); $authorized = false; $findApiKey = ApiKey::where('api_key', $apiKey)->where('api_secret', $apiSecret)->first(); if ($findApiKey) { if ($findApiKey->enable_whitelisted_ips) { if (in_array($ipAddress, explode(',', $findApiKey->whitelisted_ips))) { $authorized = true; } } else { $authorized = true; } } if (!$authorized) { return response()->json(['error' => 'Unauthorized'], 401); } return $next($request); } }