我看过了,我的是Laravel 5.3 Windows ....这样说把,我用Auth验证通过了,可以打印Auth::user()里面的内容出来,但跳转到Auth::check(),就卡住了...打印Auth::user()为空
那具体问题,我怎么和你讨论?这里又说不清楚..
加QQ?76708633...想和你深入探讨..
session设置?我基本没动过呢..
兄弟我也看了你的帖子,我基本和你一样,但我在路由上加web,也没用..
我使用Auth进行登录验证,Auth::attempt 验证通过后,页面进行跳转到用户中心,但是经过中间Auth::check()进行验证,就无法验证通过..
不知道什么问题?求指教..
{
路由文件
// 后台
Route::group(['namespace' => 'Backend', 'prefix' => 'Backend', 'middleware' => ['auth.admin']], function () {
Route::get('center', 'CenterController@index');
});
// 登录
Route::group(['middleware' => ['web']], function () {
// 后台登录
Route::get('Backend/login', 'Backend\MemberController@login');
Route::post('Backend/login', 'Backend\MemberController@in');
Route::post('Backend/logout', 'Backend\LoginController@logout');
});
}
这个是后台中间件..
/**
* @abstract 后台登录前中间件
* @author Yxl <zccem@163.com>
*/
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class AuthAdmin {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next) {
if (!Auth::guard('admin')->check()) {
if ($request->ajax() || $request->wantsJson()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('Backend/login');
}
}
return $next($request);
}
}
登录页面.验证已经通过..但就是上面中间件那里check()就不行.查看user()为空.
<?php
/**
* @abstract 后台登录控制器
* @author Yxl <zccem@163.com>
*/
namespace App\Http\Controllers\Backend;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use Validator;
class MemberController extends Controller {
/**
* @abstract 登录页面
*/
public function login() {
return view('backend.member.index');
}
/**
* @abstract 登入
*/
public function in(Request $request) {
if ($request->ajax()) {
$validator = Validator::make($request->all(), [
'username' => 'required|max:50',
'password' => 'required|max:50',
]);
if ($validator->fails()) {
return response()->json($validator->errors());
}
if (!Auth::guard('admin')->attempt(['username' => $request->input('username'), 'password' => $request->input('password'), 'is_using' => 'On'], $request->input('remember_me'))) {
// The user is not active, not suspended, and exists.
return response()->json('认证用户失败!!');
}
return response()->json(TRUE);
}
return;
}
/**
* @abstract 忘记密码
*/
public function forget(Request $request) {
if ($request->ajax()) {
}
return view('backend.member.forget');
}
/**
* @abstract 注销用户
*/
public function logout() {
Auth::logout();
return;
}
}