where('status', 'success') ->first(); if (!$history || !$history->affiliate_url) { abort(404, 'Short link not found or invalid.'); } // Detect if request is from a crawler bot (Zalo, Facebook, etc.) $userAgent = strtolower(request()->header('User-Agent', '')); $bots = ['zalo', 'facebookexternalhit', 'telegrambot', 'twitterbot', 'slackbot', 'googlebot', 'crawler']; $isBot = false; foreach ($bots as $bot) { if (str_contains($userAgent, $bot)) { $isBot = true; break; } } if ($isBot) { return view('short_link_preview', compact('history')); } // Increment click count for real users $history->increment('clicks'); return redirect()->away($history->affiliate_url); } }