Laravel Session method Useless ha

Source: Internet
Author: User
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']);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.