Php 认证拉威尔
当分派方法Php 认证拉威尔,php,laravel,laravel-5.2,Php,Laravel,Laravel 5.2,当分派方法Auth::trunt和Auth::check返回true,然后重定向到路由admin class LoginController extends Controller { public function login(LoginRequest $request) { if (Auth::attempt($request->only(['login', 'password']))) { var_dump(Auth::chec
Auth::trunt
和Auth::check
返回true
,然后重定向到路由admin
class LoginController extends Controller {
public function login(LoginRequest $request)
{
if (Auth::attempt($request->only(['login', 'password']))) {
var_dump(Auth::check()); // true
return redirect()->intended('admin');
}
return back();
}
}
路由admin
have中间件
class AdminMiddleware
{
public function handle($request, Closure $next)
{
var_dump(Auth::check()); // false
if (!Auth::check()) {
return view('login');
}
return $next($request);
}
}
然后重定向方法
Auth::check
返回false
,为什么会发生这种情况?将代码替换为:
use Illuminate\Http\Response;
use Closure;
use Auth;
class AdminMiddleware
{
public function handle($request, Closure $next)
{
if (!Auth::check()) {
return new Response(view('login'));
}
return $next($request);
}
}
将代码替换为:
use Illuminate\Http\Response;
use Closure;
use Auth;
class AdminMiddleware
{
public function handle($request, Closure $next)
{
if (!Auth::check()) {
return new Response(view('login'));
}
return $next($request);
}
}
这可能是会话问题,请检查cookie设置是否正确。具体设置是什么?config->session?确保您的管理中间件在会话初始化时位于
web
组中间件之后。谢谢,但现在VerifyCsrfToken.php第135行中出现另一个问题FatalErrorException:在非对象上调用成员函数setCookie()
@khoteyVitaly使用标记,否则我看不到您发布了,不管怎样,这并不是很有帮助,你有没有检查哪一行导致这一点?是否来自管理中间件?可能是会话问题,请检查cookie设置是否正确。具体设置是什么?config->session?确保您的管理中间件在会话初始化时位于web
组中间件之后。谢谢,但现在VerifyCsrfToken.php第135行中出现另一个问题FatalErrorException:在非对象上调用成员函数setCookie()
@khoteyVitaly使用标记,否则我看不到您发布了,不管怎样,这并不是很有帮助,你有没有检查哪一行导致这一点?它是来自管理中间件吗?不要使用试试这个作为你的答案。好的答案应该提供关于问题和解决方案的解释。如果您确信您的答案是正确的,则无需使用尝试此操作
,只需执行此操作,因为
或将您的代码替换为
。如果您不确定,请使用注释而不是答案。不要使用尝试此作为您的答案。好的答案应该提供关于问题和解决方案的解释。如果您确信您的答案是正确的,则无需使用尝试此操作
,只需执行此操作,因为
或将您的代码替换为
。如果您不确定,请使用注释而不是答案。