Skip to content

Commit b8505a2

Browse files
committed
easier configuration
1 parent b87f341 commit b8505a2

File tree

5 files changed

+317
-10
lines changed

5 files changed

+317
-10
lines changed

README.md

-9
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ Inform Google Search [Indexing API](https://developers.google.com/search/apis/in
1414
composer require noud/laravel-google-indexing-api
1515
```
1616

17-
2) Now follow the provider steps at [Google Api Client Wrapper](https://github.com/pulkitjalan/google-apiclient#laravel) and publish the config file.
18-
1917
## Configuration
2018

2119
1) Add these settings to your ```.env```.
@@ -24,13 +22,6 @@ GOOGLE_SERVICE_ENABLED=true
2422
GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION="/var/www/seo/config/google/google-service-account.json"
2523
```
2624

27-
2) Add the indexing scope to ```config/google.php```, like so:
28-
```
29-
'scopes' => [
30-
'https://www.googleapis.com/auth/indexing'
31-
],
32-
```
33-
3425
## Usage
3526

3627
Here is a usage example:

composer.json

+7
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,12 @@
1919
"psr-4": {
2020
"GoogleIndexing\\": "src/"
2121
}
22+
},
23+
"extra": {
24+
"laravel": {
25+
"providers": [
26+
"GoogleIndexing\\Providers\\IndexingServiceProvider"
27+
]
28+
}
2229
}
2330
}

composer.lock

+269-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/google.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'https://www.googleapis.com/auth/indexing'
5+
];
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace GoogleIndexing\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class IndexingServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Make config publishment optional by merging the config from the package.
11+
*
12+
* @return void
13+
*/
14+
public function register()
15+
{
16+
$this->mergeConfigFrom(
17+
__DIR__.'/../../config/google.php',
18+
'google.scopes'
19+
);
20+
}
21+
22+
/**
23+
* Add the given configuration to the existing configuration.
24+
*
25+
* @param string $path
26+
* @param string $key
27+
* @return void
28+
*/
29+
protected function mergeConfigFrom($path, $key)
30+
{
31+
// get the scopes
32+
$config = $this->app['config']->get($key, []);
33+
// add our scope to the existing scopes
34+
$this->app['config']->set($key, array_merge($config, require $path));
35+
}
36+
}

0 commit comments

Comments
 (0)