designbycode / laravel-brevo
wrapper for brevo-php
Fund package maintenance!
Designbycode
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 1
Type:package
Requires
- php: ^8.2||^8.3||^8.4
- getbrevo/brevo-php: ^2.0
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- mockery/mockery: ^1.6
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- spatie/laravel-ray: ^1.35
This package is auto-updated.
Last update: 2025-02-03 06:54:48 UTC
README
The LaravelBrevo package is a Laravel wrapper for integrating with the Brevo API (formerly Sendinblue). It simplifies interactions with Brevo's email marketing and contact management features, allowing you to manage contacts, subscribe/unsubscribe users, and retrieve contact information seamlessly within your Laravel application.
This version of the documentation demonstrates how to use the package via the Facade for cleaner and more expressive code.
Use Cases
This package is ideal for:
-
Email Marketing:
- Subscribe users to mailing lists.
- Unsubscribe users from mailing lists.
- Update user attributes (e.g., name, preferences).
-
Contact Management:
- Retrieve contact details.
- Create or update contacts in Brevo.
-
Automation:
- Automatically add new users to Brevo lists during registration.
- Sync user data between your application and Brevo.
Support us
Installation
You can install the package via composer:
composer require designbycode/laravel-brevo
You can publish the config file with:
php artisan vendor:publish --tag="brevo"
Add your Brevo API key to the .env file:
BREVO_API_KEY=your-api-key
Configuration
return [ 'api_key' => env('BREVO_API_KEY', ''), ];
api_key: Your Brevo API key. This is required to authenticate API requests.
Usage
Retrieve Contact Information.
To retrieve details for a specific contact by email:
use Designbycode\LaravelBrevo\Facades\Brevo; if ($contact = Brevo::getContactInfo('test@example.com')) { echo "Contact Name: " . $contact->getAttributes()->name; } else { echo "Contact not found."; }
Subscribe a Contact
To subscribe a contact to a mailing list:
use Designbycode\LaravelBrevo\Facades\Brevo; if ($success = Brevo::subscribe('test@example.com', $listId)) { echo "Contact subscribed successfully!"; } else { echo "Failed to subscribe contact."; }
Unsubscribe a Contact
To unsubscribe a contact from a mailing list:
use Designbycode\LaravelBrevo\Facades\Brevo; if ($success = Brevo::unsubscribe('test@example.com', $listId)) { echo "Contact unsubscribed successfully!"; } else { echo "Failed to unsubscribe contact."; }
Methods
Brevo::getContactInfo(string $email): ?GetExtendedContactDetails
- Retrieves contact details for the specified email.
- Returns
null
if the contact is not found.
Brevo::subscribe(string $email, int $listId, array $attributes = []): bool
- Subscribes a contact to a mailing list.
- Creates a new contact if they don't exist, or updates an existing contact.
- Returns
true
on success,false
on failure.
Brevo::unsubscribe(string $email, int $listId): bool
- Unsubscribes a contact from a mailing list.
- Returns
true
on success,false
on failure.
Error Handling
The package handles API errors gracefully:
- 404 Not Found: Logs a warning and returns
null
orfalse
. - 500 Server Error: Logs an error and returns
false
. - Other exceptions are logged and handled appropriately.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.