Laravel session out the box not working


I've created a new laravel installation and the first thing I'm trying to do it just confirm sessions are working:

Route::get('/', function () { $value = Request::session()->get('key'); if (is_null($value)) { Request::session()->set('key', md5(rand())); } dd(Request::session()->get('key')); return view('welcome'); });

I'm hoping here that session 'key' is stored, then, on the next refresh, it will output (dd) the same key value each time. However, it doesn't. I get a different value for 'key' each time. So I guess session data is not being stored?

If it helps, below is the config/session.php content:

'driver' => env('SESSION_DRIVER', 'file'), ... 'files' => storage_path('framework/sessions'), ...

My .env has the following:

... SESSION_DRIVER=file ...

And permissions on the folders are:

$ ll /var/www/o-eco/website/storage/framework total 24 drwxrwxr-x 1 ubuntu www-data 4096 Oct 3 02:33 ./ drwxrwxr-x 1 ubuntu www-data 4096 Oct 3 02:33 ../ drwxrwxr-x 1 ubuntu www-data 4096 Oct 3 02:33 cache/ -rw-rw-r-- 1 ubuntu www-data 103 Oct 3 02:33 .gitignore drwxrwxr-x 1 ubuntu www-data 4096 Jan 13 10:59 sessions/ drwxrwxr-x 1 ubuntu www-data 4096 Jan 13 10:59 views/ $ ll /var/www/o-eco/website/storage/framework/sessions total 16 drwxrwxr-x 1 ubuntu www-data 4096 Jan 13 10:59 ./ drwxrwxr-x 1 ubuntu www-data 4096 Oct 3 02:33 ../ -rw-rw-r-- 1 ubuntu www-data 258 Jan 13 10:59 5xqzOeb6f5lLKyvZIwOeonutkmluREfcaQ5owTNE -rw-rw-r-- 1 ubuntu www-data 14 Oct 3 02:33 .gitignore

Note: this time, I'm developing within a vagrant box so all files are ubuntu:www-data. Also, I've even tried setting the sessions dir/files to 777 but still no difference.

Also, I have two cookies: XSRF-TOKEN and laravel_session. These both remain unchanged on each refresh.


Just use save(); after put it will works

Just try this

Session::put('key', md5(rand())); Session::save();


removed dd()

Route::get('/', function () { $value = Request::session()->get('key'); echo $value; if (is_null($value)) { Request::session()->set('key', md5(rand())); } return view('welcome'); });


  • SQL Server Integrated Security from an Azure Web Site
  • Grid creating extra spacing that I don't want
  • Furthest-point Voronoi diagram in Java
  • Getting IIS6 to play nice with WordPress Pretty Permalinks
  • React Router and Arbitrary Query Params: Page Refreshes Unintentionally on Load?
  • WP7 difficulties binding data to listbox itemssource - won't refresh
  • Update varbinary(MAX) field in SQLServer 2012 Lost Last 4 bits
  • Merge Module leaving files during uninstall
  • netsh acl setting (need alternative method - registry settings?)
  • how to set variables in a php include file?
  • Low TTL with Leveled Compaction, should I reduce gc_grace_seconds to improve read performance withou
  • Redirect STDERR in OPEN pipe comand. Perl Linux
  • Silverlight DependencyProperty.SetCurrentValue Equivalent
  • Keep this build forever option - Jenkins
  • Converting a WriteableBitmap image ToArray in UWP
  • Email verification using google app script and google forms
  • Recording logins for password protected directories
  • Is there any way to access browser form field suggestions from JavaScript?
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Deserializing XML into class C#
  • Hazelcast - OperationTimeoutException
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Circular dependency while pushing http interceptor
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Is there a mandatory requirement to switch app.yaml?
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • embed rChart in Markdown
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Busy indicator not showing up in wpf window [duplicate]
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app