我已经修改了Laravel的供应商文件,该文件位于
/vendor/laravel/framework/src/Illuminate/Auth/Guard.php
但是在更新Laravel时它将被覆盖。
我正在寻找一种将代码放在/ app中的位置以防止覆盖的方法。
修改的功能是
public function UpdateSession() {
$this->session->set('type', $type); //==> Set Client Type
}
文件上还有一个新功能:
public function type() {
return $this->session->get('type'); //==> Get Client Type
}
上面的代码在我的应用程序中的很多地方都被调用过。
任何的想法?
步骤:
1-创建myGuard.php
class myGuard extends Guard
{
public function login(Authenticatable $user, $remember = false)
{
$this->updateSession($user->getAuthIdentifier(), $user->type);
if ($remember) {
$this->createRememberTokenIfDoesntExist($user);
$this->queueRecallerCookie($user);
}
$this->fireLoginEvent($user, $remember);
$this->setUser($user);
}
protected function updateSession($id, $type = null)
{
$this->session->set($this->getName(), $id);
$this->session->set('type', $type);
$this->session->migrate(true);
}
public function type()
{
return $this->session->get('type');
}
}
2-在AppServiceProvider或新服务提供商或route.php中:
public function boot()
{
Auth::extend(
'customAuth',
function ($app) {
$model = $app['config']['auth.model'];
$provider = new EloquentUserProvider($app['hash'], $model);
return new myGuard($provider, App::make('session.store'));
}
);
}
3-在config / auth.php中
'driver' => 'customAuth',
4-现在您可以使用此
Auth::type();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句