- How do I install spatie/laravel-mailcoach-sdk in a Laravel app?
- Install it with Composer using composer require spatie/laravel-mailcoach-sdk. Laravel auto-discovers the service provider and registers the Mailcoach facade, so no manual provider registration is needed. Publish the config file with vendor:publish and add your Mailcoach API token and endpoint to your .env file. There are no database migrations or other dependencies to install.
- Does laravel-mailcoach-sdk work with both self-hosted Mailcoach and Mailcoach Cloud?
- Yes. The SDK supports both self-hosted Mailcoach (version 6 and up) and hosted Mailcoach, also known as Mailcoach Cloud. You point the SDK at the right endpoint via configuration, so the same code works against either installation. Only the API token and base URL differ between the two.
- Which Laravel versions does spatie/laravel-mailcoach-sdk support?
- As of v1.5.0 the package supports Laravel 12 and 13. If you are on an older Laravel release, you should downgrade to v1.4.x or earlier of the SDK. Check the composer.json constraints on the repository before upgrading to confirm the exact framework requirement for your version.
- How do I configure the Mailcoach API token and endpoint?
- Publish the package config with vendor:publish and set the API token and endpoint values in your .env file. For self-hosted Mailcoach, the endpoint should be the URL of your Mailcoach installation; for Mailcoach Cloud it is the hosted API URL. No database tables need to be created, so configuration is limited to credentials and the base URL.
- How do I create and send a campaign with the Mailcoach facade?
- Call Mailcoach::createCampaign() with an email_list_uuid, a name and the campaign fields such as title and content. The returned campaign object lets you call sendTest() to deliver a test email to a specific address or send() to send the full campaign. This keeps campaign management inside your Laravel codebase without writing your own HTTP client.
- How do I paginate through email list subscribers with the SDK?
- Fetch subscribers with Mailcoach::emailList($uuid)->subscribers(), which returns a paginated collection. Mailcoach paginates at a limit of 1000 by default, and you call next() on the result to load the following page. A do/while loop that reassigns the collection from next() is the documented pattern for iterating every subscriber.
- How does the Eloquent subscriber integration in v1.6.0 work?
- Version 1.6.0 adds an Eloquent integration that ties Mailcoach subscriber records directly to your application models such as User or Member, reducing hand-rolled subscriber mapping and UUID storage. Because it is a new, single-pull-request feature, confirm the exact ergonomics, such as trait versus interface and the lifecycle hook points, in the package docs before designing around it. Test bulk operations, mass updates that bypass model events, soft deletes and re-syncs of existing records carefully.
- How do I test code that uses the Mailcoach SDK?
- The package ships with Mailcoach::fake(), which lets you swap the real API client for a fake inside your Laravel tests. This means your test suite does not need network access or a live Mailcoach account. You can assert that calls such as campaign creation or subscriber sync were made without hitting the Mailcoach API.
- Will model-level subscriber sync slow down user-facing requests?
- The SDK does not natively support asynchronous operations, so if Subscriber syncing runs synchronously during model saves, it adds Mailcoach API latency to that request path. The common mitigation is to defer the sync into a queued job or wrap it in ShouldQueue-style handling. Validate the behaviour against your existing observers and bulk imports before relying on it in production.
- Is spatie/laravel-mailcoach-sdk official and safe for production?
- It is an unofficial SDK published by Spatie, and its functionality depends on the stability of the Mailcoach API, so endpoint or rate-limit changes may require SDK updates. The core facade-based API client is mature, but the v1.6.0 Eloquent integration is roughly one pull request old and should be adopted with a test harness rather than trusted by default. If you prefer to avoid the dependency, the alternative is calling the Mailcoach REST API directly with Laravel's HTTP client.