Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Controller Util Laravel Package

zenstruck/controller-util

Symfony controller utilities that cut boilerplate: traits for entity lookups with automatic 404 handling, flash messages, redirects, form processing, and template rendering, keeping your controllers small, consistent, and focused on the action itself.

View on GitHub
Deep Wiki
Context7

Getting Started

This is a small, archived Symfony 2-era utility package. Treat it as a legacy helper, not a foundation for new work.

  1. Check whether you should install it at all. It was last released in 2015, has zero dependents, and is archived. If you are on Symfony 4/5/6+, stop here and use AbstractController with JsonResponse/RedirectResponse instead. If you are maintaining a Symfony 2.x application, continue.
  2. Read the package source first. It is tiny. Open README.md, then src/, then tests/. The README is the authoritative place for the exact helper names; tests/ shows the expected response status codes, headers, and bodies.
  3. Check composer.json compatibility. Confirm the PHP constraint and the symfony/http-foundation constraint before requiring it. Run composer why-not zenstruck/controller-util if installation fails.
  4. First use case: returning a JSON, redirect, or error response from a controller without extending Symfony's base Controller class. The point of the package is to let you build responses in plain controller classes or services without pulling in the framework controller base.

Typical usage shape (the exact class/method API is defined in src/ — verify before copying):

// In a controller or service that does not extend the framework base Controller
return $responseHelper->json(['status' => 'ok']);

The first win is usually replacing ad-hoc new JsonResponse(...) or new RedirectResponse(...) calls with one consistent helper.

Implementation Patterns

  • Thin controllers, response helper injected. Register the package helper as a service and inject it into controllers or application services. This avoids both $this->get(...) calls and inheriting from the framework base controller.
  • Wrap it in your own response factory. Do not let the package's API leak across the codebase. Create an ApiResponseFactory that delegates to the package and adds your conventions (envelope shape, error codes, cache headers). This makes later migration to native Symfony responses trivial.
  • Standardize API envelopes. Use the helper for success and error JSON responses, then normalize status codes and Content-Type in one place. This is the highest-value pattern for day-to-day use.
  • Use it for non-controller response creation. Event listeners, exception handlers, and other services can build responses without depending on the controller layer. That decoupling is the package's main architectural benefit.
  • Redirect-after-POST. Use the redirect helper for 302/303 responses, and be explicit about which status code you want. Keep the target URL construction in your own code.
  • Error helpers. Use not-found/forbidden helpers to avoid repetitive new Response(..., 404) code, but keep user-facing messages in your application layer.
  • Test helpers as plain classes. Because response construction is decoupled from the framework controller, you can unit test status codes, headers, and payloads without booting a kernel. Integration-test only the final controller wiring.
  • Migration shim. If you must keep the package temporarily, put it behind an interface such as ResponseFactoryInterface and bind it to the package implementation. Swapping to native Symfony response classes later becomes a one-line container change.

Gotchas and Tips

  • Abandoned and unmaintained. No security or compatibility updates. Pin an exact version, audit the source once, and do not build new features on top of it. Zero dependents means little community validation.
  • Symfony 2 assumptions. The package predates modern Symfony. Expect friction with Symfony 3/4+ autowiring, return types, and PHP 7/8 deprecations. Test installation before planning any refactor.
  • "Without common dependencies" does not mean dependency-free. It typically means avoiding the framework controller base, not avoiding symfony/http-foundation. Responses still depend on HttpFoundation classes.
  • Header defaults may surprise you. Verify that JSON responses actually set Content-Type: application/json and that redirects use the status code you expect. Do not assume the helper applies your application's standard headers.
  • JSON encoding behavior. Old code may use encoding flags or error handling that differs from modern JsonResponse. Check how encoding failures are surfaced.
  • Debugging responses. Dump getStatusCode(), headers->all(), and getContent() rather than relying on browser output. If the helper is a service, confirm registration with bin/console debug:container.
  • Extension points are limited. Prefer composition: decorate or wrap the helper. Forking the package is almost never worth it for a package this small.
  • Modern replacement path. AbstractController::json()/redirect() or direct JsonResponse/RedirectResponse usage covers nearly everything this package does, with ongoing support. Plan removal rather than long-term adoption.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource