---
title: "DI and actions — Campaigns for Laravel | Roundly"
description: "Inject CampaignManager instead of the facade, or run the prepare, start, cancel and recipient actions directly — with the facade-to-action map."
url: https://roundly-consulting.com/open-source/docs/campaigns-for-laravel/without-facade
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Campaigns for Laravel](https://roundly-consulting.com/open-source/docs/campaigns-for-laravel.md)

# DI and actions

The facade is the recommended default, not the only way in. Three equivalent entry points run the same code:

- The Campaigns facade — the shortest form, used throughout these docs.
- The manager, RoundlyConsulting\\Campaigns\\CampaignManager — the facade root, a container singleton, injected through the constructor. Same API, an explicit dependency and no static calls.
- Actions — single-purpose classes with execute(), for composing into your own actions, jobs and commands.

## Inject the manager

```php
use RoundlyConsulting\Campaigns\CampaignManager;

final class LaunchSpringSale
{
    public function __construct(private CampaignManager $campaigns) {}

    public function __invoke(iterable $subscribers): void
    {
        $campaign = $this->campaigns->create('Spring sale', '<p>50% off</p>')->to($subscribers)->prepare();

        $this->campaigns->start($campaign);
    }
}
```

## Call an action

Every write is an action. Build the Campaign and its CampaignRecipient objects yourself and run them:

```php
use Illuminate\Support\Str;
use RoundlyConsulting\Campaigns\Actions\CancelCampaignAction;
use RoundlyConsulting\Campaigns\Actions\PrepareCampaignAction;
use RoundlyConsulting\Campaigns\Actions\StartCampaignAction;
use RoundlyConsulting\Campaigns\Campaign;
use RoundlyConsulting\Campaigns\CampaignRecipient;

$campaign = app(PrepareCampaignAction::class)->execute(
    new Campaign(uuid: (string) Str::uuid(), subject: 'Spring sale', content: '<p>50% off</p>', fromName: 'Shop', fromAddress: 'no-reply@shop.tld'),
    [new CampaignRecipient(uuid: (string) Str::uuid(), name: 'John Doe', reachableAt: 'john@doe.tld')],
);

app(StartCampaignAction::class)->execute($campaign);
app(CancelCampaignAction::class)->execute($campaign->uuid);
```

## Facade method → action

| Action | Facade |
| --- | --- |
| `PrepareCampaignAction` | `Campaigns::prepare(), create()->prepare()` |
| `StartCampaignAction` | `Campaigns::start(), campaign()->start(), create()->dispatch()` |
| `CancelCampaignAction` | `Campaigns::cancel(), campaign()->cancel(), campaigns:cancel` |
| `MarkRecipientProcessedAction` | `Campaigns::campaign()->markProcessed()` |
| `MarkRecipientFailedAction` | `Campaigns::campaign()->markFailed()` |

The actions take the plain value objects: PrepareCampaignAction::execute(Campaign, iterable $recipients), StartCampaignAction and CancelCampaignAction::execute(Campaign|string), MarkRecipientProcessedAction::execute(Campaign, CampaignRecipient) and MarkRecipientFailedAction::execute(Campaign, CampaignRecipient, string $error).

Campaigns::fake() replaces the manager in the container as well as behind the facade, so injected managers, the campaigns:cancel command and delivery jobs all record into it. An action you resolve and call yourself bypasses the fake and runs for real. ChangeCampaignStatusAction — the one status transition the lifecycle actions and the batch callback share — and FinishCampaignAction — what the batch runs once every delivery job ran — are @internal, so don’t call them from your code.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/campaigns-for-laravel.md)
