PHP code example of jeffersongoncalves / laravel-beehiiv
1. Go to this page and download the library: Download jeffersongoncalves/laravel-beehiiv library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jeffersongoncalves / laravel-beehiiv example snippets
// config/beehiiv.php
return [
'api_key' => env('BEEHIIV_API_KEY', ''),
'publication_id' => env('BEEHIIV_PUBLICATION_ID'),
'default_limit' => env('BEEHIIV_DEFAULT_LIMIT', 10),
];
use JeffersonGoncalves\Beehiiv\Facades\Beehiiv;
$publications = Beehiiv::publications()->list();
$publication = Beehiiv::publications()->get('pub_00000000-0000-0000-0000-000000000000');
// List (supports email, status, tier, cursor, expand filters)
$subscriptions = Beehiiv::subscriptions()->list(filters: ['email' => '[email protected] ']);
$subscription = Beehiiv::subscriptions()->get('sub_00000000-0000-0000-0000-000000000000');
$subscription = Beehiiv::subscriptions()->create([
'email' => '[email protected] ',
'reactivate_existing' => false,
'send_welcome_email' => true,
'utm_source' => 'newsletter',
]);
Beehiiv::subscriptions()->update('sub_00000000-0000-0000-0000-000000000000', ['tier' => 'premium']);
Beehiiv::subscriptions()->delete('sub_00000000-0000-0000-0000-000000000000');
// Or target a different publication explicitly
Beehiiv::subscriptions()->list(publicationId: 'pub_11111111-1111-1111-1111-111111111111');
$posts = Beehiiv::posts()->list(filters: ['status' => 'confirmed']);
$post = Beehiiv::posts()->get('post_00000000-0000-0000-0000-000000000000');
$post = Beehiiv::posts()->create([
'title' => 'Hello World',
'subtitle' => 'A short subtitle',
'status' => 'draft',
]);
Beehiiv::posts()->delete('post_00000000-0000-0000-0000-000000000000');
Beehiiv::segments()->list();
Beehiiv::segments()->get('seg_00000000-0000-0000-0000-000000000000');
Beehiiv::automations()->list();
Beehiiv::automations()->get('aut_00000000-0000-0000-0000-000000000000');
Beehiiv::referralProgram()->get();
use JeffersonGoncalves\Beehiiv\Exceptions\BeehiivException;
try {
Beehiiv::subscriptions()->get('does-not-exist');
} catch (BeehiivException $e) {
logger()->error($e->getMessage(), $e->errorBody());
}
bash
php artisan vendor:publish --tag=beehiiv-config