Skip to content

Commit 3e439d8

Browse files
committed
update readme file
1 parent 53ba1c4 commit 3e439d8

File tree

1 file changed

+98
-20
lines changed

1 file changed

+98
-20
lines changed

README.md

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
# wrapper for brevo-php
2-
1+
## Overview
32
[![Latest Version on Packagist](https://img.shields.io/packagist/v/designbycode/laravel-brevo.svg?style=flat-square)](https://packagist.org/packages/designbycode/laravel-brevo)
43
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/designbycode/laravel-brevo/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/designbycode/laravel-brevo/actions?query=workflow%3Arun-tests+branch%3Amain)
54
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/designbycode/laravel-brevo/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/designbycode/laravel-brevo/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
65
[![Total Downloads](https://img.shields.io/packagist/dt/designbycode/laravel-brevo.svg?style=flat-square)](https://packagist.org/packages/designbycode/laravel-brevo)
76

8-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
7+
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.
98

10-
## Support us
9+
This version of the documentation demonstrates how to use the package via the Facade for cleaner and more expressive code.
10+
11+
12+
## Use Cases
13+
This package is ideal for:
14+
1. Email Marketing:
15+
* Subscribe users to mailing lists.
16+
* Unsubscribe users from mailing lists.
17+
* Update user attributes (e.g., name, preferences).
18+
19+
2. Contact Management:
20+
* Retrieve contact details.
21+
* Create or update contacts in Brevo.
1122

12-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-brevo.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-brevo)
23+
3. Automation:
24+
* Automatically add new users to Brevo lists during registration.
25+
* Sync user data between your application and Brevo.
26+
27+
28+
## Support us
1329

14-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
1530

16-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
1731

1832
## Installation
1933

@@ -23,39 +37,103 @@ You can install the package via composer:
2337
composer require designbycode/laravel-brevo
2438
```
2539

26-
You can publish and run the migrations with:
40+
You can publish the config file with:
2741

2842
```bash
29-
php artisan vendor:publish --tag="laravel-brevo-migrations"
30-
php artisan migrate
43+
php artisan vendor:publish --tag="laravel-brevo-config"
3144
```
3245

33-
You can publish the config file with:
46+
Add your Brevo API key to the .env file:
3447

3548
```bash
36-
php artisan vendor:publish --tag="laravel-brevo-config"
49+
BREVO_API_KEY=your-api-key
3750
```
3851

39-
This is the contents of the published config file:
40-
52+
## Configuration
4153
```php
4254
return [
55+
'api_key' => env('BREVO_API_KEY', ''),
4356
];
57+
````
58+
api_key: Your Brevo API key. This is required to authenticate API requests.
59+
60+
61+
62+
## Usage
63+
### Retrieve Contact Information.
64+
65+
To retrieve details for a specific contact by email:
66+
```php
67+
use Designbycode\LaravelBrevo\Facades\Brevo;
68+
69+
$contact = Brevo::getContactInfo('[email protected]');
70+
71+
if ($contact) {
72+
echo "Contact Name: " . $contact->getAttributes()->name;
73+
} else {
74+
echo "Contact not found.";
75+
}
4476
```
77+
### Subscribe a Contact
78+
To subscribe a contact to a mailing list:
4579

46-
Optionally, you can publish the views using
80+
```php
81+
use Designbycode\LaravelBrevo\Facades\Brevo;
4782

48-
```bash
49-
php artisan vendor:publish --tag="laravel-brevo-views"
83+
$contact = Brevo::getContactInfo('[email protected]');
84+
85+
if ($contact) {
86+
echo "Contact Name: " . $contact->getAttributes()->name;
87+
} else {
88+
echo "Contact not found.";
89+
}
5090
```
5191

52-
## Usage
92+
### Unsubscribe a Contact
93+
To unsubscribe a contact from a mailing list:
5394

5495
```php
55-
$laravelBrevo = new Designbycode\LaravelBrevo();
56-
echo $laravelBrevo->echoPhrase('Hello, Designbycode!');
96+
use Designbycode\LaravelBrevo\Facades\Brevo;
97+
98+
$success = Brevo::unsubscribe('[email protected]', 'list-123');
99+
100+
if ($success) {
101+
echo "Contact unsubscribed successfully!";
102+
} else {
103+
echo "Failed to unsubscribe contact.";
104+
}
57105
```
58106

107+
### Methods
108+
`Brevo::getContactInfo(string $email): ?GetExtendedContactDetails`
109+
* Retrieves contact details for the specified email.
110+
* Returns `null` if the contact is not found.
111+
112+
`Brevo::subscribe(string $email, string $listId, array $attributes = []): bool`
113+
* Subscribes a contact to a mailing list.
114+
* Creates a new contact if they don't exist, or updates an existing contact.
115+
* Returns `true` on success, `false` on failure.
116+
117+
`Brevo::unsubscribe(string $email, string $listId): bool`
118+
* Unsubscribes a contact from a mailing list.
119+
* Returns `true` on success, `false` on failure.
120+
121+
### Error Handling
122+
The package handles API errors gracefully:
123+
* 404 Not Found: Logs a warning and returns `null` or `false`.
124+
* 500 Server Error: Logs an error and returns `false`.
125+
* Other exceptions are logged and handled appropriately.
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
59137
## Testing
60138

61139
```bash

0 commit comments

Comments
 (0)