laravel session method is useless

WBOY
Release: 2016-08-04 09:20:31
Original
857 people have browsed it

Why doesn’t the session method work?

Reply content:

Why doesn’t the session method work?

<code>use Illuminate\Support\Facades\Session;

Session::put('key', 'value');
$value = Session::get('key');
echo $value;</code>
Copy after login

Let me tell you the reason. Laravel's session mechanism is only stored uniformly after your class method is executed. That is to say, after you call session([foo,bar]);, it will not be directly stored in the session. Instead, it will be stored after the entire logic execution is completed. If you need to access session information in real time, you can add a Session::save(); and it will be stored.
There is another situation, that is, if your code has a forced exit such as exit, etc., or there is an internal code error, the previously set session value cannot be stored.

Don’t thank me, I just stayed in the pit for too long, /(ㄒoㄒ)/~~

The posture you are using is wrong, please refer to [Laravel 5.2 Documentation] Service——Session

<code> // 从session中获取数据...
    $value = session('key');

    // 存储数据到session...
    session(['key' => 'value']);</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template