Skip to content

Commit

Permalink
✨ Implement GoogleWebhookController
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Oct 2, 2018
1 parent 0f853f7 commit 5a42e4e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
22 changes: 22 additions & 0 deletions app/Http/Controllers/GoogleWebhookController.php
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers;

use App\Synchronization;
use Illuminate\Http\Request;

class GoogleWebhookController extends Controller
{
public function __invoke(Request $request)
{
if ($request->header('x-goog-resource-state') !== 'exists') {
return;
}

Synchronization::query()
->where('id', $request->header('x-goog-channel-id'))
->where('resource_id', $request->header('x-goog-resource-id'))
->firstOrFail()
->ping();
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/VerifyCsrfToken.php
Expand Up @@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware
* @var array
*/
protected $except = [
//
'google/webhook',
];
}
3 changes: 2 additions & 1 deletion routes/web.php
Expand Up @@ -17,10 +17,11 @@

Auth::routes();

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

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

0 comments on commit 5a42e4e

Please sign in to comment.