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,
],
];
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'));
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();