Last active
July 29, 2024 08:44
-
-
Save thiagorb/d4f4afaafa23a7a564b5675db952fbb2 to your computer and use it in GitHub Desktop.
Extend session store in Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Session; | |
class EncryptedStore extends \Illuminate\Session\EncryptedStore | |
{ | |
public function get($key, $default = null) | |
{ | |
$originalValue = parent::get($key, $default); | |
if (is_null($originalValue)) { | |
// do something | |
} | |
return $originalValue; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Session; | |
class SessionManager extends \Illuminate\Session\SessionManager | |
{ | |
protected function buildSession($handler) | |
{ | |
if ($this->app['config']['session.encrypt']) { | |
return $this->buildEncryptedSession($handler); | |
} | |
return new Store($this->app['config']['session.cookie'], $handler); | |
} | |
protected function buildEncryptedSession($handler) | |
{ | |
return new EncryptedStore( | |
$this->app['config']['session.cookie'], $handler, $this->app['encrypter'] | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Session; | |
class SessionServiceProvider extends \Illuminate\Session\SessionServiceProvider | |
{ | |
protected function registerSessionManager() | |
{ | |
$this->app->singleton('session', function ($app) { | |
return new SessionManager($app); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Session; | |
class Store extends \Illuminate\Session\Store | |
{ | |
public function get($key, $default = null) | |
{ | |
$originalValue = parent::get($key, $default); | |
if (is_null($originalValue)) { | |
// do something | |
} | |
return $originalValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment