The session method doesn't work, huh?
Reply content:
The session method doesn't work, huh?
use Illuminate\Support\Facades\Session;Session::put('key', 'value');$value = Session::get('key');echo $value;
Let me tell you the reason, Laravel's session mechanism is actually after your class method executes the unified storage, that is, after you call session([foo,bar]); will not be stored directly in the session, but after the completion of the entire logical execution is stored, if you need to access the session information in real-time , you can add one to Session::save(); store it.
Another situation is that if your code has a forced exit such as exit, or an internal code error, you cannot store the session value of the previous set.
Don't thank me, I just spent too much time in the pit,/(ㄒoㄒ)/~~
You are using the wrong posture, please refer to the [Laravel 5.2 documentation] service--session
// 从session中获取数据... $value = session('key'); // 存储数据到session... session(['key' => 'value']);