The array argument is used to pass values for the URL wildcard segments needed by the Route; it is not used for passing arbitrary data.
If you were to visit the URL directly; how would the $page_title variable be set?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
EDIT: I genuinely don't know what changed, but it is working now. I cleared my cache, and then just rewrote the return as:
return redirect()->route('items.index')->with('success', 'Item was created');
And it is working exactly as expected. No issues.
In a controller, in the store method, I am trying to use
return redirect()->route('items.index', ['page_title' => 'Items'])->with('success', 'Item was successfully saved');
but when I use this code, I get the error:
Undefined variable: page_title
The page title is in a partial blade template that is included in the main template. so the variable page_title isn't in the index.blade.php template for the item, it is instead in a different blade template in a different directory.
Please or to participate in this conversation.