Abb*_*ami 5 php laravel laravel-5
我修改了Laravel的供应商文件
/vendor/laravel/framework/src/Illuminate/Auth/Guard.php
但是在更新Laravel时会被覆盖.
我正在寻找一种方法将代码放在我的/ app中,以防止覆盖.
修改的功能是
public function UpdateSession() {
$this->session->set('type', $type); //==> Set Client Type
}
Run Code Online (Sandbox Code Playgroud)
此外,该文件还有一个新功能:
public function type() {
return $this->session->get('type'); //==> Get Client Type
}
Run Code Online (Sandbox Code Playgroud)
上面的代码在我的应用程序的许多地方被调用.
任何的想法?
步骤:
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');
}
}
Run Code Online (Sandbox Code Playgroud)
2-在AppServiceProvider或新的服务提供者或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'));
}
);
}
Run Code Online (Sandbox Code Playgroud)
在config/auth.php中为3-
'driver' => 'customAuth',
Run Code Online (Sandbox Code Playgroud)
4-现在你可以使用它
Auth::type();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3389 次 |
| 最近记录: |