huysynf/laravel-indexnow
最新稳定版本:v1.0.15
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
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-08