---
title: "DI and actions — Likes for Laravel | Roundly"
description: "Skip the facade: inject LikeManager or call a single-purpose action with a LikeData DTO — the facade method → action map."
url: https://roundly-consulting.com/open-source/docs/likes-for-laravel/without-facade
language: en
---

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

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

# DI and actions

The facade is the recommended default, not the only way in. Three entry points run the same code: the Likes facade (shortest), the manager RoundlyConsulting\\Likes\\LikeManager — the facade’s root — injected through the constructor (same API, explicit dependency, no static calls), and actions (single-purpose classes with execute(), for composing into your own actions, jobs and commands).

## Inject the manager

```php
use RoundlyConsulting\Likes\LikeManager;

final class LikePost
{
    public function __construct(private LikeManager $likes) {}

    public function __invoke(User $user, Post $post): bool
    {
        return $this->likes->actor($user)->as('love')->like($post);
    }
}
```

## Call an action

```php
use RoundlyConsulting\Likes\Actions\LikeAction;
use RoundlyConsulting\Likes\Actions\LikeManyAction;
use RoundlyConsulting\Likes\DataTransferObjects\LikeData;

app(LikeAction::class)->execute(new LikeData($user, $post, 'love'));
app(LikeManyAction::class)->execute($user, [$post, $comment], 'love');
```

## Facade method → action

| Facade / builder method | Action |
| --- | --- |
| `like()` | `LikeAction` |
| `unlike()` | `UnlikeAction` |
| `toggle()` | `ToggleLikeAction` |
| `react()` | `SwitchReactionAction` |
| `likeMany()` | `LikeManyAction` |
| `unlikeMany()` | `UnlikeManyAction` |

- LikeAction, UnlikeAction, ToggleLikeAction and SwitchReactionAction take a LikeData DTO — actor, likeable and an optional type, checked against the reactions allowlist. LikeManyAction and UnlikeManyAction take the actor, an iterable of likeables and an optional type.
- An action never resolves an actor for you — pass one explicitly.
- Likes::fake() also swaps injected LikeManagers, so constructor-injected code is recorded too. Calling an action directly bypasses the fake’s recording.

## 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/likes-for-laravel.md)
