PHP code example of huysynf / laravel-indexnow

1. Go to this page and download the library: Download huysynf/laravel-indexnow library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

huysynf / laravel-indexnow example snippets


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,
    ],
];

'models' => [
    \App\Models\Post::class,
    \App\Models\Page::class,
],

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);
    }
}

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);

use Huysynf\LaravelIndexNow\Events\ContentPublished;

// Fire event to submit URL
event(new ContentPublished('https://example.com/page'));

'dashboard' => [
    'enabled' => true,
    'route' => 'admin/indexnow',
    'middleware' => ['web', 'auth'],
    'layout' => 'layouts.app',
],

'middleware' => [
    'api',
    'auth:sanctum',     // Require authentication
    'throttle:60,1',    // Rate limiting: 60 requests per minute
],

'middleware' => ['api', 'auth:sanctum'],

'middleware' => ['api', 'throttle:60,1'],

'middleware' => ['api', 'your-custom-middleware'],

'rate_limit' => [
    'enabled' => true,
    'cooldown' => 60, // seconds
],

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();
bash
php artisan vendor:publish --tag=indexnow-config
bash
php artisan migrate
bash
php artisan indexnow:generate-key
bash
php artisan queue:work