acorn icon indicating copy to clipboard operation
acorn copied to clipboard

Flash session messages not available in Blade template from laravel controller in Sage 11

Open WebCimes opened this issue 4 months ago • 1 comments

Version

11

What did you expect to happen?

Flash messages set in the controller (using session()->flash() or ->with()) should persist and be available on the next request when redirecting back to a WordPress page using a Blade template (template-contact.blade.php).

What actually happens?

The session only contains regular values (e.g. session()->put()), but all flash messages are lost. The _flash array in the session remains empty (old and new are both empty). This only occurs when redirecting back to a page rendered via a Blade template attached to a WordPress page (e.g. using Template Name: header in Sage 11).

However, if I route the page manually via a Laravel-style controller and return a view(), flash messages work as expected.

Steps to reproduce

Create a Blade file in resources/views named template-contact.blade.php with the comment header:

{{-- Template Name: Contact --}}

Assign this template to a WordPress page named "Contact".

Inside the Blade template, add a form:

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

In routes/web.php, add:

use App\Http\Controllers\ContactController;

Route::post('contact/send', [ContactController::class, 'send'])->name('contact.send');

Create ContactController.php and define the send() method:


public function send(Request $request)
{
    session()->put('test1', 'value1');
    session()->flash('test2', 'value2');
    return redirect()->back()->with('test3', 'value3');
}

Submit the form and inspect the session (e.g. via dd(session()->all()) in the template).

You will notice that:

test1 is present

test2 and test3 (flash data) are missing

_flash is empty

Now test the same form inside a controller-rendered view (e.g. create index route and controller with return view('template-contact')) — flash data appears correctly.

System info

No response

Log output


Please confirm this isn't a support request.

Yes

WebCimes avatar Aug 01 '25 14:08 WebCimes

Thanks for the report! I've moved this to the Acorn repo.

Log1x avatar Aug 01 '25 20:08 Log1x