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

Rewire Laravel Package

recodex-id/rewire

Rewire is a Laravel package for cleanly swapping and rebinding application services. It simplifies dependency rewiring, keeps container configuration explicit, and helps you replace implementations without scattering boilerplate across service providers.

View on GitHub
Deep Wiki
Context7

Getting Started

Rewire v1.3.0 is the release that turns the package from a routing/scaffolding helper into a "site essentials" layer: legal pages, cookie consent, SEO meta, spam protection, and production hardening all ship together. Start by confirming what the package actually registers in your app rather than assuming defaults:

  1. Install and inspect the surface area

    composer require recodex-id/rewire:^1.3
    php artisan vendor:publish --tag=rewire-config
    php artisan vendor:publish --tag=rewire-migrations   # if the release ships any
    php artisan route:list | grep -i rewire
    

    The three things to read first are config/rewire.php (feature toggles), the package's service provider (what middleware/routes/components it auto-registers), and any published views under resources/views/vendor/rewire.

  2. Turn features on deliberately. The five feature areas are almost certainly config-gated. Check for keys like legal, cookie_consent, seo, spam, hardening and enable only what you want in config/rewire.php. Enabling everything at once on an existing app is how you get surprise middleware and surprise redirects.

  3. First use case: legal pages + cookie banner. This is the lowest-risk, highest-value path.

    • Publish/seed the legal page content (privacy policy, terms, cookie policy) and replace the placeholder text — the package can ship templates, but the copy is legally yours to own.
    • Drop the consent component into your main layout (<x-rewire::cookie-consent /> or whatever the published view namespace exposes — verify the exact tag from the published views).
    • Confirm the consent cookie is actually being set and read before you wire any analytics behind it.
  4. Then layer SEO meta into your base layout's <head>, and lastly enable spam protection on public forms and the hardening middleware — those two touch request/response behaviour and deserve their own deploy.

Implementation Patterns

Layout-level composition for SEO meta. Rather than sprinkling meta tags per view, resolve meta once in a base layout or a view composer, and let individual pages override via a @section/stack. A workable pattern:

{{-- layouts/app.blade.php --}}
<head>
    <x-rewire::seo-meta :model="$seoSubject ?? null" />
    @stack('meta')
</head>

Then in a page view: @push('meta')<meta name="robots" content="noindex">@endpush. This keeps the package as the default and gives you an escape hatch per page (useful for thank-you pages, filtered listings, and paginated archives that shouldn't be indexed).

Consent-gated script loading. The consent banner is only half the feature — the value is in not loading trackers until consent exists. Keep a single source of truth:

@if (rewire()->consentGiven('analytics'))
    <script src="{{ asset('js/analytics.js') }}" defer></script>
@endif

If the package exposes a helper/facade, use it rather than reading $_COOKIE directly; if it doesn't, wrap the cookie read in one small service class so the key name and versioning live in one place.

Spam protection as a form-level trait or middleware, not per-field hand-rolling. Apply the package's protection to public-facing forms (contact, newsletter, comments) and skip it on authenticated POSTs and API endpoints. Pair it with Laravel's throttle middleware — the package's spam layer handles bots, rate limiting handles volume; they're complementary, not redundant.

Hardening as an environment-scoped middleware group. Register the production-hardening middleware only where it belongs:

// bootstrap/app.php (Laravel 11+) or Kernel.php
$middleware->appendToGroup('web', Rewire\Middleware\SecurityHeaders::class);

…and gate HSTS/HTTPS-forcing on app()->isProduction(). Applying the full hardening set in local dev tends to break asset loading and redirect loops against Valet/Herd/Sail.

Legal pages as content, not code. Treat the published legal views as editable content, keep them in version control, and add a test that asserts the routes return 200 and contain a "last updated" date. Legal copy changes are exactly the kind of thing that silently breaks when someone refactors routes.

Gotchas and Tips

  • Re-publishing overwrites your edits. If you customised legal page views or the consent banner in v1.2.x, a vendor:publish --force will clobber them. Diff published files before overwriting, and consider keeping overrides in your own view namespace instead of resources/views/vendor/rewire.

  • Consent state and cache. If you serve cached pages (response cache, CDN, Cloudflare), the consent banner markup must be identical for all users — render it client-side or as a static component with no server-side consent branching in the cached HTML. Server-side @if (consentGiven()) inside a cached page will leak one user's consent state to everyone.

  • Cookie name/version changes silently reset consent. If v1.3.0 renamed or versioned the consent cookie, every existing visitor is asked again. That's usually acceptable (and arguably correct), but call it out to stakeholders before deploy so it isn't mistaken for a bug.

  • Hardening middleware + proxies. HTTPS forcing and secure-cookie enforcement depend on TrustProxies being configured correctly. Behind a load balancer without trusted proxies you'll get redirect loops or cookies that never set. Verify TrustProxies before enabling hardening in staging.

  • SEO meta and pagination. Confirm how the package handles ?page= — paginated pages need rel=prev/next or noindex decisions, and canonical URLs must strip tracking params. Test with a query string, not just a clean URL.

  • Spam protection vs. webhooks and API clients. Honeypot/time-trap approaches break non-browser clients. Exclude api/* and any webhook routes from the spam middleware group, and check whether the package's protection is registered globally (it shouldn't be).

  • Config caching. After editing config/rewire.php, run php artisan config:clear. Feature toggles read from config won't reflect changes under config:cache, and this is the single most common "the feature isn't working" report.

  • Extension points to prefer. Favour the package's published config and Blade components over subclassing its middleware or overriding its routes. Middleware and route names are the most likely things to change in a 1.4.x; config keys and view overrides are the stable contract.

  • Verify before trusting the release notes. The changelog entry is a single squashed commit covering five features, which means no per-feature docs in the diff. Read the actual service provider and config file — don't assume a feature is opt-in just because it's listed as a "feature."

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.
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment