bentonow/bento-laravel-sdk is a Laravel package for laravel sdk for bento.
It currently has 28 GitHub stars and 70.820 downloads on Packagist (latest version v1.4.0).
Install it with composer require bentonow/bento-laravel-sdk.
Discover more Laravel packages by bentonow
or browse all Laravel packages to compare alternatives.
Last updated
[!TIP] Need help? Join our Discord or email [email protected] for personalized support.
The Bento Laravel SDK makes it quick and easy to send emails and track events in your Laravel applications. We provide powerful and customizable APIs that can be used out-of-the-box to manage subscribers, track events, and send transactional emails. We also expose low-level APIs so that you can build fully custom experiences.
Get started with our 📚 integration guides, or 📘 browse the SDK reference.
🐶 Battle-tested by High Performance SQLite (a Bento customer)!
❤️ Thank you @aarondfrancis for your contribution.
❤️ Thank you @ziptied for your contribution.
Install the package via Composer:
composer require bentonow/bento-laravel-sdk
After installing, run the install command to set up your environment interactively:
php artisan bento:install
You will be prompted for:
.env fileIf you decline automatic .env modification, the command will display the required environment variables for you to copy and add manually. You will also see links to the Bento Laravel documentation and the Bento app.
Note: The install command uses Laravel Prompts for a modern, interactive setup experience. This requires Laravel 10+ and PHP 8.1+.
If you prefer, you can manually add the following to your .env file:
BENTO_PUBLISHABLE_KEY="your-publishable-key"
BENTO_SECRET_KEY="your-secret-key"
BENTO_SITE_UUID="your-site-uuid"
MAIL_MAILER=bento
MAIL_FROM_ADDRESS="[email protected]"
You can verify your transactional email configuration by running:
php artisan bento:test
This command will:
MAIL_FROM_ADDRESSNote: The test command requires Bento to be configured as your default mailer (
MAIL_MAILER=bento) and a validMAIL_FROM_ADDRESSto be set.
Track custom events in your application:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\EventData;
$data = collect([
new EventData(
type: '$completed_onboarding',
email: "[email protected]",
fields: [
"first_name" => "John",
"last_name" => "Doe"
]
)
]);
return Bento::trackEvent($data)->json();
Import subscribers into your Bento account:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\ImportSubscribersData;
$data = collect([
new ImportSubscribersData(
email: "[email protected]",
first_name: "John",
last_name: "Doe",
tags: ["lead", "mql"],
removeTags: ["customers"],
fields: ["role" => "ceo"]
),
]);
return Bento::importSubscribers($data)->json();
Search your site for a subscriber:
use Bentonow\BentoLaravel\Facades\Bento;
return Bento::findSubscriber("[email protected]")->json();
Creates a subscriber in your account and queues them for indexing:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\CreateSubscriberData;
$data = new CreateSubscriberData(email: "[email protected]");
return Bento::createSubscriber($data)->json();
Execute a command and change a subscriber's data:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\CommandData;
use Bentonow\BentoLaravel\Enums\Command;
$data = collect([
new CommandData(Command::REMOVE_TAG, "[email protected]", "test")
]);
return Bento::subscriberCommand($data)->json();
Returns a list of tags in your account:
use Bentonow\BentoLaravel\Facades\Bento;
return Bento::getTags()->json();
Creates a custom tag in your account:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\CreateTagData;
$data = new CreateTagData(name: "example tag");
return Bento::createTag($data)->json();
The field model is a simple named key value pair, think of it as a form field:
use Bentonow\BentoLaravel\Facades\Bento;
return Bento::getFields()->json();
Creates a custom field in your account:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\CreateFieldData;
$data = new CreateFieldData(key: "last_name");
return Bento::createField($data)->json();
Returns a list of broadcasts in your account:
use Bentonow\BentoLaravel\Facades\Bento;
return Bento::getBroadcasts()->json();
Create new broadcasts to be sent:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\CreateBroadcastData;
use Bentonow\BentoLaravel\DataTransferObjects\ContactData;
use Bentonow\BentoLaravel\Enums\BroadcastType;
$data = Collect([
new CreateBroadcastData(
name: "Campaign #1 Example",
subject: "Hello world Plain Text",
content: "<p>Hi {{ visitor.first_name }}</p>",
type: BroadcastType::PLAIN,
from: new ContactData(
name: "John Doe",
emailAddress: "[email protected]"
),
inclusive_tags: "lead,mql",
exclusive_tags: "customers",
segment_id: "segment_123456789",
batch_size_per_hour: 1500
),
]);
return Bento::createBroadcast($data)->json();
Returns a list of site stats:
use Bentonow\BentoLaravel\Facades\Bento;
return Bento::getSiteStats()->json();
Returns a list of a segments stats:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\SegmentStatsData;
$data = new SegmentStatsData(segment_id: "123");
return Bento::getSegmentStats($data)->json();
Returns an object containing data for a specific report:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\ReportStatsData;
$data = new ReportStatsData(report_id: "456");
return Bento::getReportStats($data)->json();
Validates the IP or domain name with industry email reputation services to check for delivery issues:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\BlacklistStatusData;
$data = new BlacklistStatusData(domain: null, ipAddress: "1.1.1.1");
return Bento::getBlacklistStatus($data)->json();
Validates the email address using the provided information to infer its validity:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\ValidateEmailData;
$data = new ValidateEmailData(
emailAddress: "[email protected]",
fullName: "John Snow",
userAgent: null,
ipAddress: null
);
return Bento::validateEmail($data)->json();
An opinionated Content moderation:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\ContentModerationData;
$data = new ContentModerationData("Its just so fluffy!");
return Bento::getContentModeration($data)->json();
Guess a subscriber's gender using their first and last name. Best for US users; based on US Census Data:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\GenderData;
$data = new GenderData("John Doe");
return Bento::getGender($data)->json();
This endpoint attempts to geolocate the provided IP address:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\GeoLocateIpData;
$data = new GeoLocateIpData("1.1.1.1");
return Bento::geoLocateIp($data)->json();
Retrieve a single email template by ID:
use Bentonow\BentoLaravel\Facades\Bento;
return Bento::getEmailTemplate(123)->json();
Update an email template's subject and/or HTML content. Only the fields you provide will be updated:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\UpdateEmailTemplateData;
$data = new UpdateEmailTemplateData(
id: 123,
subject: "Updated Subject",
html: "<p>Updated content</p>"
);
return Bento::updateEmailTemplate($data)->json();
Returns a list of sequences in your account. Supports pagination:
use Bentonow\BentoLaravel\Facades\Bento;
return Bento::getSequences()->json();
// With pagination
return Bento::getSequences(page: 2)->json();
Create a new email template within a sequence:
use Bentonow\BentoLaravel\Facades\Bento;
use Bentonow\BentoLaravel\DataTransferObjects\CreateSequenceEmailData;
$data = new CreateSequenceEmailData(
sequenceId: "123",
subject: "Day 1: Welcome!",
html: "<p>Thanks for signing up</p>",
delayInterval: "days",
delayIntervalCount: 1
);
return Bento::createSequenceEmail($data)->json();
Returns a list of workflows in your account. Supports pagination:
use Bentonow\BentoLaravel\Facades\Bento;
return Bento::getWorkflows()->json();
// With pagination
return Bento::getWorkflows(page: 2)->json();
Get all responses for a form by its identifier:
use Bentonow\BentoLaravel\Facades\Bento;
return Bento::getFormResponses("my-form-id")->json();
Tag a subscriber with automation triggers:
use Bentonow\BentoLaravel\Facades\Bento;
Bento::tagSubscriber("[email protected]", "vip");
Remove a tag from a subscriber with automation triggers:
use Bentonow\BentoLaravel\Facades\Bento;
Bento::removeTag("[email protected]", "vip");
Add a subscriber with automation triggers:
use Bentonow\BentoLaravel\Facades\Bento;
Bento::addSubscriber("[email protected]", [
"first_name" => "John",
"last_name" => "Doe"
]);
Unsubscribe a subscriber with automation triggers:
use Bentonow\BentoLaravel\Facades\Bento;
Bento::removeSubscriber("[email protected]");
Update custom fields on a subscriber with automation triggers:
use Bentonow\BentoLaravel\Facades\Bento;
Bento::updateFields("[email protected]", [
"plan" => "pro",
"company" => "Acme Inc"
]);
Track a purchase for LTV calculation with automation triggers. Amounts should be in cents:
use Bentonow\BentoLaravel\Facades\Bento;
Bento::trackPurchase("[email protected]", [
"unique" => ["key" => "order-123"],
"value" => ["amount" => 9999, "currency" => "USD"],
"cart" => [
["product_id" => "sku-1", "quantity" => 1, "price" => 9999]
]
]);
Track a custom event with automation triggers:
use Bentonow\BentoLaravel\Facades\Bento;
Bento::track(
"[email protected]",
'$completed_onboarding',
fields: ["first_name" => "John"],
details: ["step" => "final"]
);
Create or update a subscriber and return the record. Throws a RuntimeException if the import fails:
use Bentonow\BentoLaravel\Facades\Bento;
$subscriber = Bento::upsertSubscriber(
email: "[email protected]",
firstName: "John",
lastName: "Doe",
tags: ["lead", "website"],
fields: ["role" => "ceo"]
);
return $subscriber->json();
Note: If the import step fails (e.g. invalid data), a
RuntimeExceptionis thrown instead of returning a partial response. Wrap the call in a try/catch if you need to handle failures gracefully:try { $subscriber = Bento::upsertSubscriber(email: "[email protected]"); } catch (\RuntimeException $e) { // Handle the failure Log::warning($e->getMessage()); }
bento.signature middleware or the BentoSignatureExclusion::class. This must be before the signed middleware to remove all utm and tracking url params.no-reply sender addresses for transactional emails. You MUST use an author you have configured as your sender address.We welcome contributions! Please see our contributing guidelines for details on how to submit pull requests, report issues, and suggest improvements.
The Bento SDK for Laravel is available as open source under the terms of the MIT License.