elfeffe/laravel-google-indexing
Composer 安装命令:
composer require elfeffe/laravel-google-indexing
包简介
Index Laravel website in Google via Indexing API
README 文档
README
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
Requirements
- PHP 8.4+
- Laravel 12 or 13
- a Google service account configured for the Indexing API
Important note
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:
Installation
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.
Configuration
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.
Basic usage
Facade
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');
Direct service usage
use Elfeffe\LaravelGoogleIndexing\LaravelGoogleIndexing; $googleIndexing = new LaravelGoogleIndexing(); $googleIndexing->update('https://example.com/page');
Custom auth config
use Elfeffe\LaravelGoogleIndexing\LaravelGoogleIndexing; $googleIndexing = LaravelGoogleIndexing::forAuthConfig( storage_path('my-google-service-account.json') );
Model indexing
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);
Helper usage
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);
Quota helpers
$helper->isQuotaExceeded(); $helper->getRemainingQuota();
Using the trait:
Article::getTodayIndexingCount(); Article::getRemainingDailyQuota(); Article::query()->needsGoogleIndexing(30)->get();
Stored records
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.
Exceptions
Quota errors throw:
Elfeffe\LaravelGoogleIndexing\Exceptions\GoogleQuotaExceededException
You should catch it if you are bulk processing URLs.
Credits
License
MIT. See LICENSE.md.
elfeffe/laravel-google-indexing 适用场景与选型建议
elfeffe/laravel-google-indexing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 59 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「google」 「seo」 「laravel」 「indexing」 「laravel-google-indexing」 「Elfeffe」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 elfeffe/laravel-google-indexing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elfeffe/laravel-google-indexing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 elfeffe/laravel-google-indexing 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Help to manage meta data on Laravel Eloquent model
Statamic Fine Seo addon
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
Magento - Force store code extension
统计信息
- 总下载量: 59
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-03