Sample data in this table looks like below:
There are multiple duplicate User's Session records present in the table.
vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php
In the above file path, we have below method
public function write($sessionId, $data)
{
$payload = $this->getDefaultPayload($data);
if (! $this->exists) {
$this->read($sessionId);
}
if ($this->exists) {
$this->getQuery()->where('id', $sessionId)->update($payload);
} else {
$payload['id'] = $sessionId;
$this->getQuery()->insert($payload);
}
$this->exists = true;
}
It checks for Session ID.
Question
Can I avoid creation of duplicate User Session Records in Session Table? Is there any flag that do so in Session Config file?
It seems to be an error in your traitement, must be like this no ? :
if (! $this->exists) {
$this->read($sessionId);
}else{
if ($this->exists) {
$this->getQuery()->where('id', $sessionId)->update($payload);
} else {
$payload['id'] = $sessionId;
$this->getQuery()->insert($payload);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With