Laravel Go✓ Human-reviewed

One redirect notice in Laravel Go

Replace one plain-text redirect notice with native session flash, explicit payload rules and escaped rendering.

Approved 2026-12-04T15:00:05.789327Z · Submission 98

One redirect notice in Laravel Go

Scope

Replace one plain-text notification after a successful form action with native session flash and an escaped view. Exclude multiple-message queues, overlays, raw HTML, important/dismiss UI, macros and toast/JS APIs. Upstream's Composer manifest declares MIT; retain applicable notices for adapted source. At the time of writing the catalog listed a Go gap, although native sessions cover this bounded use. Check get-recipe's current port catalog. This guidance has not been exercised in your app; verify it below.

Source behaviour

src/Laracasts/Flash/FlashNotifier.php appends Message objects and flashes flash_notification; error selects danger. Falsy messages update the last object instead of appending, and Message.php::update filters falsy attributes. LaravelSessionStore.php calls framework flash. src/views/message.blade.php renders raw message HTML and forgets the session key. tests/FlashTest.php exercises levels/queues/overlays and store calls, not a real multi-request lifecycle.

This extraction deliberately uses a new key, one last-write-wins message, escaped text, empty-text rejection and acceptance of string "0". It is not the upstream fluent/falsy/HTML API. Keep incompatible callers on their original path.

Implementation

  1. Capture selected producer/view/redirect fixtures, existing session middleware and driver. Inventory excluded queue/HTML/modal callers before changing dependencies. Preserve the successful action's redirect status/location.
  2. Authorize the action and enforce CSRF/validation before database work. Flash success only after commit; never imply a failed/rolled-back write succeeded. Use a fixed/trusted redirect destination and don't expose exception internals or secrets in text.
  3. Use a JSON-safe payload and native session Flash("app_notice", payload) on a session-enabled web request. Do not use plain Put or a process-global variable. The inspected Go session source supports flash aging and JSON-copy persistence. It declares a Go 1.27 toolchain and generic methods; reconcile the installed framework/toolchain instead of transplanting a newer API into an older Go app.
  4. Consume the key once in the destination layout, validate decoded shape/level and pass text as an ordinary string through HTML template escaping. The inspected Get plus Forget avoids relying on typed generic pull syntax but is not an atomic delivery operation. Keep only fixed CSS class mappings; never cast user text to trusted HTML. One layout owns consumption.
  5. Keep the app's actual session middleware/driver persistence and failure handling. Native flash lasts through the next request, not until the user necessarily sees a page; intermediate requests and concurrent tabs can consume it. Use existing session/request serialization where required, not a new queue or unbounded reflash loop. Jobs cannot write to an arbitrary user's request session.

Complete pure payload constructor, using only the standard library. Returned text is intentionally unescaped for the final template to escape once. This does not itself persist or consume session data:

import "fmt"

func notice(level, text string) (map[string]string, error) {
    switch level {
    case "error": level = "danger"
    case "danger", "success", "info", "warning":
    default: return nil, fmt.Errorf("unsupported notice level")
    }
    if text == "" { return nil, fmt.Errorf("empty notice") }
    return map[string]string{"level": level, "text": text}, nil
}

Acceptance checklist

  • Execute POST→redirect→GET→refresh with the actual driver/middleware: successful committed action displays once; refresh does not. Authorization/validation/rollback failures cannot display success. Preserve exact redirect status/location.
  • Check every allowed level, error→danger mapping, rejected unknown level/empty text and accepted "0". Two writes deliberately keep only the last message, not a queue.
  • Render HTML-looking text, ampersands/quotes and Unicode through the real template. It must remain text; no trusted-HTML cast or dynamic CSS injection. Retain accessible status/alert behavior.
  • Exercise malformed session payloads, no-session routes, intermediate redirects, logout/rotation, two destination components, concurrent requests/tabs and two separate users. Document the native shared-session delivery limitations rather than promising exactly once.
  • Run go test ./... with the app's required toolchain, relevant race tests and request/template integration tests. Search package helpers/views and other consumers before removal; record versions, request traces and deliberate differences.

Sources

  • Reference; MIT declared in composer.json: src/Laracasts/Flash/FlashNotifier.php, Message.php, LaravelSessionStore.php, src/views/message.blade.php, tests/FlashTest.php. No standalone license file was present in this checkout; resolve notices before source redistribution.
  • Framework source checked: session/session.go (Flash, Get, Forget, AgeFlash), session/session_test.go, go.mod. This is unversioned source requiring its declared toolchain, not a claimed release.
  • Port options: check get-recipe's current port catalog (sourced from Package Port) at implementation time.