Index Laravel website in Google via Indexing API
elfeffe/laravel-google-indexing is a Laravel package for index laravel website in google via indexing api.
It currently has 4 GitHub stars and 52 downloads on Packagist (latest version v1.0.0).
Install it with composer require elfeffe/laravel-google-indexing.
Discover more Laravel packages by elfeffe
or browse all Laravel packages to compare alternatives.
Last updated
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:
GoogleIndexable trait for modelsGoogle 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.0
Publish the config:
php artisan vendor:publish --tag=laravel-google-indexing-config
Publish the migration:
php artisan vendor:publish --tag=laravel-google-indexing-migrations
The 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_messageindexable_type / indexable_idThis lets you avoid unnecessary resubmissions and track recent indexing activity.
Quota errors throw:
Elfeffe\LaravelGoogleIndexing\Exceptions\GoogleQuotaExceededException
You should catch it if you are bulk processing URLs.
MIT. See LICENSE.md.