NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Reviews for Laravel

DI and actions

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

  • The Reviews facade — the shortest form, used throughout these docs.
  • The manager — RoundlyConsulting\Reviews\ReviewsManager, the Macroable container singleton and the facade root. Inject it for the same API with an explicit dependency and no static calls.
  • Actions — each flat verb resolves one small action class from the container. Call execute() on it to compose reviews into your own actions, jobs and commands.

Injecting the manager

use RoundlyConsulting\Reviews\ReviewsManager;

final class ProductReviewController
{
    public function __construct(private ReviewsManager $reviews) {}

    public function store(Product $product, Request $request): Review
    {
        return $this->reviews->for($product)->by($request->user())->rating(5)->create();
    }
}

Reviews::fake() swaps the injected instance too — ReviewsFake extends ReviewsManager, so a class that type-hints the manager receives the recording fake in tests.

Calling an action

use RoundlyConsulting\Reviews\Actions\CreateReview;
use RoundlyConsulting\Reviews\Actions\MarkReviewVerified;
use RoundlyConsulting\Reviews\DataTransferObjects\CreateReviewData;

$review = app(CreateReview::class)->execute(new CreateReviewData(
    author: $user,
    reviewable: $restaurant,
    content: 'Great place',
    title: 'Loved it',
    rating: 5,
    meta: collect(['visit' => 'dinner']),
));

app(MarkReviewVerified::class)->execute($review, verified: true);

Facade method → action

Facade methodActionSignatureFires
Reviews::create($data) — and for()->by()->create()CreateReviewexecute(CreateReviewData $data): ReviewReviewCreated
Reviews::approve($review)ApproveReviewexecute(Review $review): ReviewReviewApproved
Reviews::reject($review, $reason)RejectReviewexecute(Review $review, ?string $reason = null): ReviewReviewRejected
Reviews::update($review, $data)UpdateReviewexecute(Review $review, UpdateReviewData $data): ReviewReviewUpdated
Reviews::delete($review)DeleteReviewexecute(Review $review): voidReviewDeleted
Reviews::respond($review, $author, $content, $title)RespondToReviewexecute(Review $parent, Model $author, string $content, ?string $title = null): ReviewReviewResponded
Reviews::vote($review, $voter, $helpful)VoteOnReviewexecute(Review $review, Model $voter, bool $helpful = true): ReviewVoteReviewVoted
Reviews::removeVote($review, $voter)RemoveReviewVoteexecute(Review $review, Model $voter): boolReviewVoteRemoved
Reviews::verify($review) / unverify($review)MarkReviewVerifiedexecute(Review $review, bool $verified = true): ReviewReviewVerified
  • CreateReviewData carries author, reviewable, content, title, rating, meta, approved, verified and photos; UpdateReviewData carries title, content, rating, meta and verified, where null means “leave unchanged”.
  • ValidatesRating (the rating range guard) and RecountReviewVotes (the denormalized vote tallies) are @internal building blocks of those actions — not for host use.
  • An action you call directly skips the manager, so Reviews::fake() does not record it.

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

By 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.