huysynf/laravel-indexnow
Composer 安装命令:
composer require huysynf/laravel-indexnow
包简介
Laravel package for IndexNow API integration - Automatically submit URLs to search engines
README 文档
README
Laravel package for IndexNow API integration. Automatically submit URLs to search engines (Bing, Google, Yandex, etc.) when content is created, updated, or deleted.
Features
✅ Automatic URL Submission - Submit URLs automatically when models change
✅ Queue Support - Async submission with retry logic
✅ Rate Limiting - Prevent duplicate submissions
✅ Event-Driven - Use Laravel events for flexible integration
✅ REST API - Full API for manual submissions
✅ Artisan Commands - CLI tools for management
✅ Statistics - Track submission success/failure
✅ Laravel 8-12 Support - Compatible with Laravel 8, 9, 10, 11, and 12
Installation
Install via Composer:
composer require huysynf/laravel-indexnow
Publish the config file (migrations are loaded automatically):
php artisan vendor:publish --tag=indexnow-config
Run migrations:
php artisan migrate
Generate an API key:
php artisan indexnow:generate-key
Configuration
Edit config/indexnow.php:
return [ // Your IndexNow API key 'api_key' => env('INDEXNOW_API_KEY', ''), // Enable/disable auto submission 'enabled' => env('INDEXNOW_ENABLED', true), // Queue configuration 'queue' => [ 'enabled' => true, 'connection' => null, 'queue' => 'default', ], // Models to watch for changes 'models' => [ // Add your models here // \App\Models\Post::class, ], ];
Usage
1. Automatic Submission (Recommended)
Add models to watch in config/indexnow.php:
'models' => [ \App\Models\Post::class, \App\Models\Page::class, ],
Implement getIndexNowUrl() method in your models:
namespace App\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { /** * Get the public URL for IndexNow submission. * * @return string|null */ public function getIndexNowUrl() { return route('posts.show', $this->slug); } }
That's it! URLs will be submitted automatically when posts are created, updated, or deleted.
2. Manual Submission via Facade
use Huysynf\LaravelIndexNow\Facades\IndexNow; // Submit a single URL IndexNow::submitUrl('https://example.com/page', 'add'); // Submit multiple URLs IndexNow::submitBatch([ 'https://example.com/page1', 'https://example.com/page2', ]); // Get statistics $stats = IndexNow::getStats(); // Resubmit failed URLs IndexNow::resubmitFailed(10);
3. Manual Submission via Events
use Huysynf\LaravelIndexNow\Events\ContentPublished; // Fire event to submit URL event(new ContentPublished('https://example.com/page'));
4. Artisan Commands
# Generate API key php artisan indexnow:generate-key # Submit URL manually php artisan indexnow:submit https://example.com/page --type=add # Migrate existing URLs from configured models # Note: Skips URLs that have ANY successful submission in history php artisan indexnow:migrate-urls # Force submission of all URLs (ignore history) php artisan indexnow:migrate-urls --force # Migrate specific model only php artisan indexnow:migrate-urls --model="App\Models\Post" # Limit number of URLs to migrate php artisan indexnow:migrate-urls --limit=100 # Process in custom chunk size php artisan indexnow:migrate-urls --chunk=50
Admin Dashboard
Optional admin dashboard UI for managing IndexNow submissions.
Access: /admin/indexnow (requires authentication by default)
Configuration (config/indexnow.php):
'dashboard' => [ 'enabled' => true, 'route' => 'admin/indexnow', 'middleware' => ['web', 'auth'], 'layout' => 'layouts.app', ],
Features:
- Statistics (weekly, success rate, total passed)
- Manual URL submission
- Resubmit failed URLs
- Recent submissions table
5. REST API
Submit URL:
POST /api/indexnow/submit Content-Type: application/json { "url": "https://example.com/page", "type": "add" }
Get Statistics:
GET /api/indexnow/stats
Get Submissions:
GET /api/indexnow/submissions?status=passed&per_page=20
Resubmit Failed:
POST /api/indexnow/resubmit Content-Type: application/json { "limit": 10 }
API Middleware Configuration
Customize middleware for API routes in config/indexnow.php:
'middleware' => [ 'api', 'auth:sanctum', // Require authentication 'throttle:60,1', // Rate limiting: 60 requests per minute ],
Common Use Cases:
Require Authentication:
'middleware' => ['api', 'auth:sanctum'],
Add Rate Limiting:
'middleware' => ['api', 'throttle:60,1'],
Custom Middleware:
'middleware' => ['api', 'your-custom-middleware'],
API Key Verification
IndexNow requires a verification file at https://yourdomain.com/{api_key}.txt.
This package automatically serves this file. After generating your API key, verify it works:
https://yourdomain.com/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6.txt
Queue Configuration
For better performance, enable queue processing:
- Set up a queue driver (database, redis, etc.)
- Run queue worker:
php artisan queue:work
Rate Limiting
The package prevents submitting the same URL multiple times within a short period (default: 60 seconds).
Configure in config/indexnow.php:
'rate_limit' => [ 'enabled' => true, 'cooldown' => 60, // seconds ],
Statistics & Monitoring
View submission statistics:
use Huysynf\LaravelIndexNow\Models\IndexNowSubmission; // Get all stats $stats = IndexNowSubmission::getStats(); // Get recent submissions $recent = IndexNowSubmission::recent(7)->get(); // Get failed submissions $failed = IndexNowSubmission::failed()->get();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Security
If you discover any security related issues, please email huyhq.developer@gmail.com instead of using the issue tracker.
Credits
- Huysynf
- Inspired by the WordPress IndexNow plugin by Microsoft Bing
License
The MIT License (MIT). Please see License File for more information.
Support
- 📧 Email: huyhq.developer@gmail.com
- 🐛 Issues: GitHub Issues
- 📖 Documentation: Full Documentation
Resources
huysynf/laravel-indexnow 适用场景与选型建议
huysynf/laravel-indexnow 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「google」 「seo」 「bing」 「laravel」 「search-engine」 「indexnow」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 huysynf/laravel-indexnow 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 huysynf/laravel-indexnow 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 huysynf/laravel-indexnow 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library for making calls to the Microsoft Translator V2 API
Search engine scrapper
Help to manage meta data on Laravel Eloquent model
Statamic Fine Seo addon
Bing Image Extractor
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-08