SessionGuard
に建てられたが、これを変更する方法がありませんので、あなたはメソッドをオーバーライドする独自のGuard
クラスを作成する必要があり、そしてあなたのGuard
クラスを使用するAuth
を教えてくれます。この情報はmy answer hereで説明されており、TokenGuard
のカスタマイズ方法について説明しています。
まず、SessionGuard
クラスを拡張する新しいGuard
クラスを作成します。新しいGuard
クラスでは、getRecallerName()
メソッドをオーバーライドして、必要な名前を返します。この例では、それはapp/Services/Auth/MySessionGuard.php
で作成されます。
namespace App\Services\Auth;
use Illuminate\Auth\SessionGuard;
class MySessionGuard extends SessionGuard
{
/**
* Get the name of the cookie used to store the "recaller".
*
* @return string
*/
public function getRecallerName()
{
return 'myprefix_'.$this->name.'_'.sha1(static::class);
}
}
あなたのクラスを作成したら、Auth
はそれについて知っている必要があります。
public function boot(GateContract $gate)
{
$this->registerPolicies($gate);
Auth::extend('mysession', function($app, $name, array $config) {
$provider = $this->createUserProvider($config['provider']);
$guard = new \App\Services\Auth\MySessionGuard($name, $provider, $app['session.store']);
// When using the remember me functionality of the authentication services we
// will need to be set the encryption instance of the guard, which allows
// secure, encrypted cookie values to get generated for those cookies.
if (method_exists($guard, 'setCookieJar')) {
$guard->setCookieJar($app['cookie']);
}
if (method_exists($guard, 'setDispatcher')) {
$guard->setDispatcher($app['events']);
}
if (method_exists($guard, 'setRequest')) {
$guard->setRequest($app->refresh('request', $guard, 'setRequest'));
}
return $guard;
});
}
をそして最後に、あなたはあなたの新しいmysession
ガードを使用するようにAuth
を伝える必要があります:あなたは、あなたのAuthServiceProvider
サービスプロバイダにboot()
方法でこれを行うことができます。これはconfig/auth.php
設定ファイルで行われます。
'guards' => [
'web' => [
'driver' => 'mysession',
'provider' => 'users',
],
],