jaybizzle/laravel-crawler-detect
Laravel Crawler Detect
A Laravel wrapper for Crawler-Detect - the web crawler detection library.
Requirements
- PHP 8.1+
- Laravel 10, 11, 12 or 13
Need support for an older version of Laravel or PHP? Use v1.3.0 of this package.
Installation
composer require jaybizzle/laravel-crawler-detect
The service provider and the Crawler facade alias are registered automatically via package auto-discovery.
Usage
use Crawler;
// Check the current visitor's user agent
if (Crawler::isCrawler()) {
// true if a crawler user agent was detected
}
// Or pass a user agent string to check
if (Crawler::isCrawler('Mozilla/5.0 (compatible; aiHitBot/2.9; +https://www.aihitdata.com/about)')) {
// true if a crawler user agent was detected
}
// Output the name of the bot that matched (if any)
echo Crawler::getMatches();
You can also type-hint the underlying class and let the container inject it:
use Jaybizzle\CrawlerDetect\CrawlerDetect;
public function index(CrawlerDetect $crawlerDetect)
{
if ($crawlerDetect->isCrawler()) {
// ...
}
}
Or use the Request macros, which detect using the current request:
use Illuminate\Http\Request;
public function index(Request $request)
{
if ($request->isCrawler()) {
// Output the name of the bot that matched (if any)
echo $request->crawler()->getMatches();
}
// Or pass a user agent string to check
if ($request->isCrawler('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')) {
// ...
}
}
Testing
composer test
License
Laravel Crawler Detect is open-sourced software licensed under the MIT license.
Related Packages
vlados/laravel-blade-crawler-detect
Boost Lighthouse and PageSpeed scores by hiding cookie banners, chat widgets and...
5,912
0
ricardofontanelli/laravel-telegram
A simple and lightweight Laravel 4 and 5 wrapper to interact with Telegram Bot.
3,653
10
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v2.1.0 | ^8.1 | ^10.0| | MIT | |
| v2.0.0 | ^8.1 | ^10.0| | MIT | |
| v1.3.0 | >=5.4.0 | MIT | ||
| v1.2.0 | >=5.4.0 | MIT | ||
| v1.1.0 | >=5.4.0 | MIT | ||
| v1.0.2 | >=5.4.0 | MIT | ||
| v1.0.1 | >=5.3.0 | MIT | ||
| v1.0.0 | >=5.3.0 | MIT |