Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Google Bundle Laravel Package

ekyna/google-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to Begin

  1. Installation

    composer require ekyna/google-bundle
    

    Add the bundle to config/bundles.php in your Laravel project:

    Ekyna\GoogleBundle\GoogleBundle::class,
    
  2. Publish Configuration Run the vendor publish command to generate the default config file:

    php artisan vendor:publish --provider="Ekyna\GoogleBundle\GoogleServiceProvider" --tag="config"
    

    This creates config/google.php with default settings.

  3. First Use Case: Google API Client Initialization Use the bundle’s service provider to initialize a Google API client in a controller or service:

    use Ekyna\GoogleBundle\Services\GoogleClient;
    
    public function __construct(GoogleClient $googleClient) {
        $this->googleClient = $googleClient;
    }
    

    Inject the GoogleClient class to interact with Google APIs (e.g., Drive, Calendar, etc.).


Implementation Patterns

Workflows

  1. Service Integration

    • Use the GoogleClient facade or dependency-injected service to interact with Google APIs.
    • Example: Fetching Google Drive files:
      $files = $this->googleClient->drive()->files()->listFiles();
      
  2. Configuration Management

    • Customize API scopes, credentials, and services in config/google.php:
      'services' => [
          'drive' => [
              'scopes' => ['https://www.googleapis.com/auth/drive'],
          ],
          'calendar' => [
              'scopes' => ['https://www.googleapis.com/auth/calendar'],
          ],
      ],
      
  3. Middleware for Authentication

    • Use the bundle’s middleware to enforce Google API authentication in routes:
      Route::middleware(['google.auth'])->group(function () {
          // Protected routes requiring Google API access
      });
      
  4. Event Handling

    • Listen for Google API events (e.g., token refresh) via Laravel’s event system:
      event(new \Ekyna\GoogleBundle\Events\TokenRefreshed($token));
      

Integration Tips

  • Laravel Mix/Blade: Use the bundle’s helpers (if available) to embed Google APIs in Blade templates or frontend assets.
  • Testing: Mock the GoogleClient in unit tests:
    $this->mock(GoogleClient::class)->shouldReceive('drive()->files()->listFiles')->andReturn($mockedFiles);
    

Gotchas and Tips

Pitfalls

  1. Missing Configuration

    • Ensure config/google.php is properly set up with valid API credentials (client ID, secret, etc.). Default values may not work out of the box.
    • Fix: Run php artisan vendor:publish --tag="config" and verify the credentials section.
  2. Scope Restrictions

    • If scopes are misconfigured in config/google.php, API requests will fail with 403 Forbidden.
    • Fix: Double-check scopes against Google’s API documentation.
  3. Token Expiry

    • Refresh tokens may expire silently. Handle Google_Auth_Exception in your code:
      try {
          $result = $this->googleClient->drive()->files()->listFiles();
      } catch (\Google_Auth_Exception $e) {
          // Log and retry or prompt user to re-authenticate
      }
      
  4. Deprecated Methods

    • The bundle may use older Google API client methods (e.g., Google_Service_*). Update to newer SDK versions if needed.

Debugging

  • Enable Debugging: Set debug: true in config/google.php to log API requests/responses.
  • Log Credentials: Avoid logging sensitive credentials. Use Laravel’s config('google.credentials') cautiously.

Extension Points

  1. Custom Services

    • Extend the bundle by creating custom services that wrap GoogleClient:
      class CustomGoogleService {
          public function __construct(GoogleClient $client) {
              $this->client = $client;
          }
      
          public function customMethod() {
              return $this->client->drive()->files()->listFiles(['q' => 'custom query']);
          }
      }
      
  2. Middleware Customization

    • Override the default authentication middleware in app/Http/Kernel.php:
      protected $routeMiddleware = [
          'google.auth' => \Ekyna\GoogleBundle\Http\Middleware\GoogleAuth::class,
      ];
      
  3. Event Listeners

    • Subscribe to bundle events (e.g., TokenRefreshed) to log or cache tokens:
      \Event::listen(\Ekyna\GoogleBundle\Events\TokenRefreshed::class, function ($event) {
          \Log::info('Token refreshed', ['token' => $event->token]);
      });
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware