All packages
Likes for Laravel
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
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
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 cryptoBy donating, you agree to our donation terms.
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.