Online
Bento

Laravel Bento Quick Start

This tutorial sets up Bento in a Laravel app using the Bento-laravel-sdk. You'll configure Bento as your mail transport, send a transactional email, and sync new users to Bento with tags and fields.

1
Setting up Your Laravel Environment

Prepare your Laravel environment. This tutorial starts with a fresh install, but the SDK works the same in existing applications.

  1. Install Laravel:
Code
composer create-project laravel/laravel bento-example
  1. Install dependencies:
Code
composer require bentonow/bento-laravel-sdk
  1. Set up Bento:
Code
php artisan bento:install
2
Configuring Your Environment

Next, configure your app to work with Bento. You can find your Bento API keys and Site_UUID in the Bento account dashboard. Don't share them or commit them to source code.

If you want Bento to handle your transactional email, the SDK includes a transport for your convenience.

  1. Open your .env file and add these lines:
Code
BENTO_SITE_UUID=your_site_uuid
BENTO_PUBLISHABLE_KEY=your_publishable_key
BENTO_SECRET_KEY=your_secret_key
  1. Update your config/mail.php file to use Bento as the mail transport:
Code
'default' => env('MAIL_MAILER', 'bento'),

'mailers' => [
  // ... other mailers ...
  'bento' => [
    'transport' => 'bento',
  ],
],
3
Creating and Using a Mailable

Create a simple mailable that uses a view and sends it as a Bento transactional email.

  1. Create a new mailable:
Code
php artisan make:mail WelcomeMail
  1. Edit app/Mail/WelcomeMail.php and make a few additions:
Code
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\Models\User;

class WelcomeMail extends Mailable
{
  use Queueable, SerializesModels;

  public function __construct(protected User $user)
  {

  }

  public function build()
  {
    return $this->view('emails.welcome')
      ->to($this->user->email);
  }
}
  1. Create a view for the email at resources/views/emails/welcome.blade.php:
Code
<h1>Welcome to our Bento Example, {{ $user->name }}!</h1>
<p>We're excited to have you on board. Get started by exploring our features.
  Or reviewing our documentation at <a href='https://docs.bentonow.com'>docs.bentonow.com</a>
</p>
  1. Use the mailable. For example, edit App\Http\Controllers\Auth\RegisteredUserController:
Code
use App\Mail\WelcomeMail;
use Illuminate\Support\Facades\Mail;

// After creating the user
$user = User::create([
  'name' => $request->name,
  'email' => $request->email,
  'password' => Hash::make($request->password),
]);

// Send the welcome email
Mail::to($user->email)->queue(new WelcomeMail($user));
4
Adding the User to Bento

When a user registers, add them as a subscriber to Bento. That way you can capture their activity and use it to trigger email flows in Bento.

  1. Jump back into RegisteredUserController:
Code
use Bentonow\BentoLaravel\BentoConnector;
use Bentonow\BentoLaravel\DataTransferObjects\CreateSubscriberData;
use Bentonow\BentoLaravel\Requests\CreateSubscriber;

// after creating the user:
$bento = new BentoConnector();

$data = collect([
  new CreateSubscriberData(email: $user->email)
]);
$request = new CreateSubscriber($data);
$bento->send($request);
5
Adding a Bento Tag to a User

Tags are great ways to segment users. In many email platforms they would be considered lists.

  1. Tag the new user based on their source (website):
Code
use Bentonow\BentoLaravel\DataTransferObjects\ImportSubscribersData;
use Bentonow\BentoLaravel\Requests\ImportSubscribers;

// After we send the email lets tag the user.

$data = collect([
  new ImportSubscribersData(
    email: $user->email,
    firstName: Str::of($user->name)
      ->after('.')
      ->before(' ')
      ->__toString(),
    lastName: Str::of($user->name)
      ->after(' ')
      ->__toString(),
    tags: ["list:website"],
    removeTags: null,
    fields: null,
  ),
]);

$request = new ImportSubscribers($data);
$bento->send($request);
6
Using Bento fields

Tags are great for segmentation, but sometimes you need to store user data to personalize emails. Fields are perfect for this.

  1. Record a user's favorite color:
Code

// assuming our sign up form included a field for favorite color
// lets update the previous tag example to include our field data.

$data = collect([
    new ImportSubscribersData(
        email: $user->email,
        firstName: Str::of($user->name)
          ->after('.')
          ->before(' ')
          ->__toString(),
        lastName: Str::of($user->name)
          ->after(' ')
          ->__toString(),
        tags: ["list:website"],
        removeTags: null,
        fields: ["fav_color" => $request->input('favorite_color')],
    ),
]);

$request = new ImportSubscribers($data);
$bento->send($request);

With Bento's API, you can quickly build a complete subscriber profile for better targeting and personalization, often with a single API call.

Next Steps

Your Laravel app is now integrated with Bento. You can send email, sync new users as subscribers, tag them, and record custom data in fields for use in emails with liquid tags.

From here, explore more Bento features and tailor them to your needs. Contact us in Discord if you need help or have suggestions!