0

I followed the documentation on Laravel 5.3's HTTP Session https://laravel.com/docs/5.3/session

Its not that to me in using this feature.

I created the sessions table via the laravel's documentation but Im not getting any stored sessions on the Application's - Seesion Storage.

Can someone shed some light on me? Thanks!

AdminController:

public function show(Request $request, $id)
{
   $request->session()->put('key', 'value');
   $value = $request->session()->get('key');
}
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
jean chu
  • 145
  • 4
  • 13

2 Answers2

0

What are your actually trying to do here? The code you have posted will not display the session value in a browser if thats what you are trying to do.

If you just want to check if the session is working, you need to re-write the function like so:

   public function show(Request $request, $id)
   {
      $request->session()->put('key', 'value');
      return $request->session()->get('key');
   }
GWed
  • 15,167
  • 5
  • 62
  • 99
  • I want to store and retrieve user session in the "sessions" table created using the "php artisan session:table" – jean chu Nov 07 '16 at 09:49
  • Ok - so you can confirm you have a sessions table created? Have you got 'database' set as your driver in config/session.php – GWed Nov 07 '16 at 09:52
  • also, what makes you think you arent saving to the session? How are you verifying this? – GWed Nov 07 '16 at 10:05
  • Yes Ive set the driver to - database in config/session.php By checking my database table sessions, there is no data that is being saved. – jean chu Nov 08 '16 at 02:14
  • Do you have a .env file that has a SESSION_DRIVER variable? This will change the default value in config. What happens if you actually return a value from the session like my code above? What is displayed in the browser? – GWed Nov 08 '16 at 07:17
  • Yes Ive set the SESSION_DRIVER to database in the .env file. Tried your code above and I didnt get anything... – jean chu Nov 09 '16 at 07:13
  • Where should I check the supposed return result? – jean chu Nov 09 '16 at 07:14
  • Just return the result to a webpage to check, or die dump it to the screen dd($request->session()->get('key')) – GWed Nov 09 '16 at 09:32
0

You can override your ENVIRONMENT (.env) variables in config/storage.php; replace env('SESSION_DRIVER', 'file') for database. Also make sure to check whether your database settings are correct in either .env or app/database.php.