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

Resend Php Laravel Package

resend/resend-php

Resend PHP is an official PHP 8.1+ client for the Resend email API. Install via Composer and send transactional emails with a clean, simple interface (e.g., $resend->emails->send) in PHP or Laravel.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Laravel-native compatibility: The package aligns with Laravel’s service container, dependency injection, and facade patterns. The provided Laravel example demonstrates seamless integration with Laravel’s config, services.php, and Mail facade.
    • Modular design: The SDK follows a resource-based structure (emails, contacts, templates, etc.), which maps cleanly to Laravel’s Eloquent-like service organization.
    • API parity: Supports Resend’s full feature set (transactional emails, templates, webhooks, contacts, automations, etc.), reducing the need for custom HTTP clients.
    • PHP 8.1+ compliance: Leverages modern PHP features (typed properties, enums) while maintaining backward compatibility with Laravel’s LTS versions (8.x–10.x).
    • Idempotency and retries: Built-in support for Idempotency-Key and rate-limiting error handling aligns with Laravel’s queue/retry systems (e.g., Illuminate\Queue).
  • Cons:

    • No Laravel-specific abstractions: Unlike laravel-notification-center or spatie/laravel-mailables, this SDK lacks built-in integration with Laravel’s Notifiable trait or Mail classes. A TPM would need to bridge this gap (e.g., via a custom facade or service provider).
    • Event/webhook handling: While the SDK supports webhooks, Laravel’s event system (e.g., Illuminate\Bus\Dispatchable) isn’t natively integrated. A TPM would need to design a listener layer (e.g., ResendWebhookHandler) to translate Resend events into Laravel events.

Integration Feasibility

  • Laravel Ecosystem Fit:
    • Service Container: The SDK’s Resend::client() can be registered in config/services.php and bound to the container, enabling dependency injection in controllers/services.
    • Mail Facade: Can be extended to work alongside Laravel’s Mail facade (e.g., via a custom ResendMailer class).
    • Queue Integration: Supports Laravel’s queue system for async email sending (e.g., Resend::emails->send() wrapped in a job).
  • Database/ORM: No direct Eloquent integration, but contacts/audiences can be mapped to Laravel models (e.g., User extending ResendContact).
  • Testing: The SDK includes PHPUnit tests, but Laravel-specific tests (e.g., for queue jobs or facades) would need to be written.

Technical Risk

  • Medium Risk:
    • API Versioning: Resend’s API evolves rapidly (e.g., recent additions like automations/events). The SDK’s maturity (v1.3.0) suggests stability, but a TPM should monitor for breaking changes.
    • Error Handling: Custom error classes (e.g., ResendException) may need wrapping to align with Laravel’s exception hierarchy (e.g., Illuminate\Mail\MailerException).
    • Performance: Batch operations (e.g., contacts->upsert) could impact Laravel’s request lifecycle. A TPM should benchmark under load.
  • Mitigation:
    • Use Laravel’s config/cache.php to store Resend API keys/endpoints.
    • Implement a ResendServiceProvider to centralize configuration and bindings.
    • Add a ResendFacade to abstract SDK calls (e.g., Resend::sendWelcomeEmail()).

Key Questions

  1. Email Workflow Strategy:
    • Will this replace Laravel’s Mail facade entirely, or coexist with it? If the latter, how will conflicts (e.g., from address validation) be resolved?
  2. Webhook Routing:
    • How will Resend webhooks be routed to Laravel’s event system? Will a ResendWebhookController be created, or will events be dispatched via a service?
  3. Template Management:
    • Will Resend templates replace Laravel’s Blade/Markdown emails, or supplement them? If hybrid, how will template IDs be mapped?
  4. Contact Sync:
    • How will Laravel models (e.g., User) sync with Resend contacts? Will a ResendContactable trait be created?
  5. Monitoring:
    • How will email delivery logs (via resend->logs) be surfaced in Laravel’s logging system (e.g., Monolog)?
  6. Fallback Strategy:
    • If Resend’s API fails, will emails fall back to Laravel’s default mailer (e.g., log, ses)? If so, how will this be implemented?

Integration Approach

Stack Fit

  • Laravel Core:
    • Service Container: Register the SDK as a singleton in AppServiceProvider:
      $this->app->singleton(Resend::class, fn() => Resend::client(config('services.resend.key')));
      
    • Configuration: Add resend to config/services.php:
      'resend' => [
          'key' => env('RESEND_API_KEY'),
          'webhook_secret' => env('RESEND_WEBHOOK_SECRET'),
      ],
      
  • Mail System:
    • Option 1: Extend Laravel’s Mailer to use the SDK:
      class ResendMailer extends Mailer {
          public function send(MailableContract $mailable, array $failures = []) {
              $resend = app(Resend::class);
              $resend->emails->send($this->prepare($mailable));
          }
      }
      
    • Option 2: Create a custom ResendMailer facade for SDK-specific calls.
  • Queue System:
    • Wrap SDK calls in Laravel jobs (e.g., SendResendEmailJob) for async processing:
      class SendResendEmailJob implements ShouldQueue {
          use Dispatchable, InteractsWithQueue;
      
          public function handle() {
              Resend::emails()->send($this->emailData);
          }
      }
      
  • Webhooks:
    • Route /resend/webhook to a controller with signature verification:
      public function handleWebhook(Request $request) {
          $payload = $request->getContent();
          $signature = $request->header('x-resend-signature');
      
          if (!Resend::verifyWebhook($payload, $signature, config('services.resend.webhook_secret'))) {
              abort(401);
          }
      
          event(new ResendWebhookReceived($payload));
      }
      

Migration Path

  1. Phase 1: SDK Integration
    • Install the package: composer require resend/resend-php.
    • Register the SDK in AppServiceProvider.
    • Replace direct HTTP calls to Resend with SDK methods (e.g., Resend::emails()->send()).
  2. Phase 2: Laravel Facade/Service Layer
    • Create a ResendFacade or ResendService to abstract SDK calls.
    • Example:
      // app/Services/ResendService.php
      class ResendService {
          public function sendWelcomeEmail(User $user) {
              return Resend::emails()->send([
                  'from' => '[email protected]',
                  'to' => $user->email,
                  'subject' => 'Welcome!',
                  'html' => view('emails.welcome', ['user' => $user]),
              ]);
          }
      }
      
  3. Phase 3: Webhook & Event Integration
    • Add webhook endpoint and event listeners.
    • Example listener:
      // app/Listeners/HandleResendEvent.php
      class HandleResendEvent {
          public function handle(ResendWebhookReceived $event) {
              $data = $event->payload;
              if ($data['event'] === 'email.bounce') {
                  // Update user's email status in DB
              }
          }
      }
      
  4. Phase 4: Contact & Template Sync
    • Sync Laravel models with Resend contacts (e.g., via model observers or jobs).
    • Example observer:
      // app/Observers/UserObserver.php
      class UserObserver {
          public function saved(User $user) {
              Resend::contacts()->upsert($user->email, [
                  'name' => $user->name,
                  'metadata' => ['user_id' => $user->id],
              ]);
          }
      }
      

Compatibility

  • Laravel Versions: Tested on PHP 8.1+; compatible with Laravel 8.x–10.x (LTS).
  • Dependencies: No conflicts with Laravel’s core packages (e.g., illuminate/mail, guzzlehttp/guzzle).
  • Database: No schema changes required, but consider adding a resend_contacts table for sync metadata.
  • Third-Party Packages:
    • spatie/laravel-activitylog: Can log Resend events.
    • spatie/laravel-medialibrary: Can integrate with Resend’s file attachments.

Sequencing

  1. **Prerequisites
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle