Submit URLs to Google's Indexing API from Laravel and track successful submissions in google_indexing_records.
This package is useful for sites that are eligible for the Google Indexing API and want:
- direct URL update/delete requests
- helper methods for quota-aware indexing
- a reusable
GoogleIndexabletrait for models - persistent records of successful submissions
- PHP 8.4+
- Laravel 12 or 13
- a Google service account configured for the Indexing API
Google only allows the Indexing API for specific content types, such as job posting and livestream pages. Check the official docs before using it broadly:
composer require elfeffe/laravel-google-indexing:^1.0Publish the config:
php artisan vendor:publish --tag=laravel-google-indexing-configPublish the migration:
php artisan vendor:publish --tag=laravel-google-indexing-migrationsThe package now reuses an existing published create_google_indexing_records_table migration if one is already present, so republishing does not create duplicate migration files.
By default the package expects the Google auth JSON at:
storage_path('google_auth_config.json')You can override it in config/laravel-google-indexing.php:
return [
'google' => [
'auth_config' => storage_path('google_auth_config.json'),
'scopes' => [
'https://www.googleapis.com/auth/indexing',
],
],
];You may also pass a JSON string or array directly when instantiating the service.
use Elfeffe\LaravelGoogleIndexing\Facades\LaravelGoogleIndexingFacade as LaravelGoogleIndexing;
LaravelGoogleIndexing::update('https://example.com/page');
LaravelGoogleIndexing::delete('https://example.com/page');
LaravelGoogleIndexing::status('https://example.com/page');use Elfeffe\LaravelGoogleIndexing\LaravelGoogleIndexing;
$googleIndexing = new LaravelGoogleIndexing();
$googleIndexing->update('https://example.com/page');use Elfeffe\LaravelGoogleIndexing\LaravelGoogleIndexing;
$googleIndexing = LaravelGoogleIndexing::forAuthConfig(
storage_path('my-google-service-account.json')
);If a model exposes a canonical URL, you can use the GoogleIndexable trait.
use Elfeffe\LaravelGoogleIndexing\Traits\GoogleIndexable;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
use GoogleIndexable;
public function getGoogleIndexingUrl(): string
{
return route('articles.show', $this);
}
}Then:
use Elfeffe\LaravelGoogleIndexing\LaravelGoogleIndexing;
$service = new LaravelGoogleIndexing();
$service->updateModel($article);The helper wraps the service with daily quota tracking based on successful submissions stored in google_indexing_records.
use Elfeffe\LaravelGoogleIndexing\Helpers\IndexingHelper;
$helper = app(IndexingHelper::class);
$helper->indexUrl('https://example.com/page');
$helper->indexUrls([
'https://example.com/page-1',
'https://example.com/page-2',
]);
$helper->indexModel($article);$helper->isQuotaExceeded();
$helper->getRemainingQuota();Using the trait:
Article::getTodayIndexingCount();
Article::getRemainingDailyQuota();
Article::query()->needsGoogleIndexing(30)->get();Successful requests are stored in google_indexing_records with:
urlstatussent_atresponse_dataerror_message- optional morph relation via
indexable_type/indexable_id
This lets you avoid unnecessary resubmissions and track recent indexing activity.
Quota errors throw:
Elfeffe\LaravelGoogleIndexing\Exceptions\GoogleQuotaExceededExceptionYou should catch it if you are bulk processing URLs.
MIT. See LICENSE.md.