Reflash a flash session from one controller to another? What exactly do you mean by that?
I land on / (homeController.php) and I do Session::flash('test', 123);
I then go to /search (searchController.php) and I do Session::all() and I no longer see 'test'. The flash data should persist for one request and yet it does not. Why is this?
It works for me. Make sure you're not doing redirects somewhere, I think a redirect might count as a request.
It would normally not behave like that. Can you show us some code?
Also, are other sessions working correctly?
There is no redirects elsewhere. Other sessions (using Session::put) are behaving correctly.
Some code for you:
<?php
class HomeController {
public function __construct()
{
Session::flash('test', '123');
}
public function showHome()
{
var_dump(Session::all());
}
}
<?php
class SearchController {
public function __construct()
{
}
public function showIndex()
{
var_dump(Session::all());
}
}
After var_dump-ing Session::all(), no flash session vars show up
You cannot have any output before setting a session variable. I believe the var_dump is interfering with your session setting. Try return a Response object in the controller action instead
I removed var_dump and it seems that the first flash works. Then I added reflash in SearchController.php, it still doesnt seem like reflash is working for me when I refresh the page.
I think you must paste a line like this session_start() at the begin of function or program for example
<?php
session_start();
class HomeController {
public function __construct()
{
Session::flash('test', '123');
}
public function showHome()
{
var_dump(Session::all());
}
}
?>
Tried that and still that same /: Any other suggestions? Thank you for any help so far.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community