session in Laravel 5.4. 36 did not save a solution to the successful problem

  • 2021-09-11 19:42:46
  • OfStack

Points for Attention in the Use of session

laravel is a php framework, when using laravel will encounter session use problems, work using session default file cache, in the use of found session()->put("key","values")  Is not set up successfully, finally turn over the source code to find that it is necessary to use when using file cache save() Method can be persisted to the database

Source: vendor/laravel/framework/src/Illuminate/Session/Store. php


/**
  * Save the session data to storage.
  *
  * @return bool
  */
 public function save()
 {
  $this->ageFlashData();

  $this->handler->write($this->getId(), $this->prepareForStorage(
   serialize($this->attributes)
  ));
  $this->started = false;
 }

Source code for write method calls due to file caching: vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler. php


/**
  * {@inheritdoc}
  */
 public function write($sessionId, $data)
 {
  $this->files->put($this->path.'/'.$sessionId, $data, true);

  return true;
 }

Summarize


Related articles: