Laravel 4:使用Config :: set更改auth.model时Auth :: user()不起作用 [英] Laravel 4: when using Config::set to change auth.model then Auth::user() not work

查看:133
本文介绍了Laravel 4:使用Config :: set更改auth.model时Auth :: user()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的laravel项目有两个登录系统.
1)使用用户名和密码
2)使用密码

我的第一个登录系统正常运行.因为auth.model具有用户"模型. 所以我在'tempSing'方法中使用'Config :: set'来获得第二次登录.

Config::set('auth.model', 'TempUser') 
Config::set('auth.table', 'temp_user')

在该代码之后,我使用下面的代码

$user= TempUser::where('secret_code','=',Input::get('code'))->first();
Auth::login($user,true);
if(Auth::check())
 return Redirect::route('getTemp');

然后该代码正常工作,并重定向到"getTemp",并在路由后生成"temp.php".但它们包括

if(Auth::check())

所以我的问题是上述逻辑不成立.使用'Config :: set'时会发生该问题,但是我在'auth.php'中手动配置了'auth.model'和'auth.table'不会发生任何错误.请帮助我.

我假设Laravel在启动应用程序时一次初始化Auth服务,因此以后对配置的编辑不再影响它.一种解决方案是自己初始化一个实例,然后使用它.

My laravel project has two login system.
1) Using user_name and Password
2) Using secret code

my 1st login system work properly. because auth.model has 'User' model. so I use 'Config::set' in 'tempSing' method to obtain 2nd login as bellow.

Config::set('auth.model', 'TempUser') 
Config::set('auth.table', 'temp_user')

After that code I use bellow code

$user= TempUser::where('secret_code','=',Input::get('code'))->first();
Auth::login($user,true);
if(Auth::check())
 return Redirect::route('getTemp');

then that code work properly and redirect to the 'getTemp' and after routing it make 'temp.php'. but their include

if(Auth::check())

so my problem is above logic not become true. that problem is occurred when using 'Config::set' but I Configured 'auth.model' and 'auth.table' manualy in 'auth.php' not happen any error. Please help me.

解决方案

I would assume Laravel initializes the Auth service once when the application is started, so later edits to configuration don't affect it anymore. A solution would be to initialize an instance yourself, and use that.

这篇关于Laravel 4:使用Config :: set更改auth.model时Auth :: user()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆