Note that there are some explanatory texts on larger screens.

plurals
  1. POlaravel session returning null inspite of setting it
    primarykey
    data
    text
    <p>Just a simple function in native php</p> <pre><code>protected function some_function(){ session_start(); if(!isset($_SESSION['a'])) { $_SESSION['a'] = 'some value'; return true; } else { return $_SESSION['a']; } } </code></pre> <p>on the 1st run, it will return bool(true) and then <code>"some value"</code> as expected.</p> <p>Applying the same to laravel session,</p> <pre><code>protected function some_function(){ $a = Session::get('abc'); if(is_null($a)){ Session::put('abc', 'some value'); //return Session::get('abc'); return true; } else { return $a; } } </code></pre> <p>By logic, on the 1st run, $a will be <code>null</code>. and then puts <code>"some value"</code> in <code>abc</code> key and returns bool(true) as expected.</p> <p><strong>However</strong> on consequent access, the <code>Session::get('abc')</code> <strong>returns null every time.</strong> so every attempt returns bool(true). </p> <p>I assumed may be session wasn't writing properly so i checked with getting the key value right after setting it. </p> <p>by commenting out the line in the above code, it returns whatever value i put in <code>Session::put('abc')</code>. <strong>So there is no error in writing the data.</strong></p> <p><strong>Problem</strong> here is trying to retrieve the value always returns <code>null</code> though i have set after the 1st request. </p> <p>Am i missing something here?</p> <hr> <h2>EDIT</h2> <p>Using database as the driver, The sessions does not get save in database. No error is outputted. Database implementation has been correct with sessions table schema as described in docs.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload