Skip to content

Commit 5a42e4e

Browse files
committed
✨ Implement GoogleWebhookController
1 parent 0f853f7 commit 5a42e4e

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Synchronization;
6+
use Illuminate\Http\Request;
7+
8+
class GoogleWebhookController extends Controller
9+
{
10+
public function __invoke(Request $request)
11+
{
12+
if ($request->header('x-goog-resource-state') !== 'exists') {
13+
return;
14+
}
15+
16+
Synchronization::query()
17+
->where('id', $request->header('x-goog-channel-id'))
18+
->where('resource_id', $request->header('x-goog-resource-id'))
19+
->firstOrFail()
20+
->ping();
21+
}
22+
}

app/Http/Middleware/VerifyCsrfToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware
1212
* @var array
1313
*/
1414
protected $except = [
15-
//
15+
'google/webhook',
1616
];
1717
}

routes/web.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
Auth::routes();
1919

20-
// Managing Google accounts.
20+
// Managing Google accounts and webhooks.
2121
Route::name('google.index')->get('google', 'GoogleAccountController@index');
2222
Route::name('google.store')->get('google/oauth', 'GoogleAccountController@store');
2323
Route::name('google.destroy')->delete('google/{googleAccount}', 'GoogleAccountController@destroy');
24+
Route::name('google.webhook')->post('google/webhook', 'GoogleWebhookController');
2425

2526
// Viewing events.
2627
Route::name('event.index')->get('event', 'EventController@index');

0 commit comments

Comments
 (0)