huysynf/laravel-indexnow

Laravel package for IndexNow API integration - Automatically submit URLs to search engines

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/huysynf/laravel-indexnow

v1.0.15 2026-01-20 14:24 UTC

This package is auto-updated.

Last update: 2026-02-08 07:03:42 UTC


README

Latest Version on Packagist Total Downloads

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:

  1. Set up a queue driver (database, redis, etc.)
  2. 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

Resources