步驟:
由1- AppServiceProvider創建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或新的服務提供商或routes.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();
那整個應用程序的類。你不應該直接搞亂Laravel的源代碼。 –