Laravel validation errors not available in WordPress Blade template after redirect

I’m using Sage 11 (with Acorn) and WordPress.

:white_check_mark: Setup

  • I have a custom WordPress page template: template-contact.blade.php
  • It contains a simple form:
{{--
  Template Name: Contact
--}}
<form method="POST" action="{{ route('contact.send') }}">
  @csrf
  <input type="text" name="name">
  <input type="email" name="email">
  <textarea name="message"></textarea>
  <button type="submit">Send</button>
</form>
  • I defined a route in routes/web.php:
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ContactController;

Route::post('contact/send', [ContactController::class, 'send'])->name('contact.send');
  • And in the controller:
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ContactController extends Controller
{
    public function send(Request $request)
    {
        $validated = $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|email|max:255',
            'message' => 'required|string|max:5000',
        ]);

        return redirect()->back()->with('status', 'ok');
    }
}

:test_tube: Problem

  • If I submit the form with a missing field (e.g. no name), the validation triggers a 302 redirect as expected.
  • However, after the redirect, in the template-contact.blade.php, there’s no way to access $errors or session() data — the session is empty: dump(session()->all()) returns [].
  • Similarly, with('status', 'ok') is not available after a successful redirect.
  • If I create a custom GET route and render a Blade view directly from Laravel (outside of the WordPress template), everything works perfectly: validation errors, session data, etc.

:magnifying_glass_tilted_left: What I tried

  • Wrapping the route in a Route::middleware('web') group.
  • Ensuring @csrf is in the form.
  • Verified session()->put('foo', 'bar') works inside a route/controller.
  • Tried injecting $errors via a view composer into all views.
  • But none of the session data appears in the WordPress-rendered Blade template (template-contact.blade.php) after redirect.

The issue seems to be when the redirect happens, WordPress routes back to the template-contact.blade.php, but does not boot the Laravel middleware stack, so session data like $errors or with('status') are never available in the template.


:speech_balloon: Question

How can I use redirect()->back()->withErrors() or with() in a controller and still access the session data (like $errors) inside a WordPress Blade view such as template-contact.blade.php?

Or:
Is there a correct way to bridge Laravel’s redirect/session system and WordPress template rendering in Sage 11?

Thanks

I updated my functions.php with this Acorn application configuration to enable Laravel middleware support:

use Roots\Acorn\Application;

Application::configure()
    ->withProviders([
        App\Providers\ThemeServiceProvider::class,
    ])
    ->withRouting(
        web: base_path('routes/web.php'),
        wordpress: true
    )
    ->withMiddleware(function (\Roots\Acorn\Configuration\Middleware $middleware) {
        $middleware->wordpress([
            Illuminate\Cookie\Middleware\EncryptCookies::class,
            Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            Illuminate\Session\Middleware\StartSession::class,
            Illuminate\View\Middleware\ShareErrorsFromSession::class,
            Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
            Illuminate\Routing\Middleware\SubstituteBindings::class,
        ]);
    })
    ->boot();

Now session()->all() inside my Blade template does return a session, for example:

array:3 [
  "_token" => "bbc8XQppL9uVE3m8iAPOmu6FQneekqLaaofT7yxO"
  "_previous" => [
    "url" => "http://localhost:7777/contact"
  ]
  "_flash" => [
    "old" => []
    "new" => []
  ]
]

The session works (session()->all() shows data), but after validation fails or with('status', 'ok'), I don’t see $errors or session('status') in the Blade template after redirect.

Any idea how to make Laravel validation and flash messages work properly inside a Sage Blade template?

did you find any way ?