在我的laravel应用程序中,我执行了php artisan make:auth并创建了所有文件以使身份验证工作。
我的AuthController.php代码:
B
我的User.php:
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';
protected $loginPath = '/login';
protected $username = 'username';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'username' => 'required|max:255|unique:users',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'hash-confirm' => md5($data['username']+Carbon::now()->resetToStringFormat()),
]);
}
}
我的routes.php:
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'username', 'email', 'password', 'hash-confirm',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
问题是,如果我输入用户名和密码错误,它会告诉我这是错误的,当它正确时它会重定向我但是当我在登录后到达页面时,Auth :: guest()是真的并且Auth :: user ()为null,因此不会创建会话。 我使用最新版本的laravel,所以我不需要在路由上放置中间件“web”组。
感谢。
答案 0 :(得分:0)
对于具有相同问题的用户,请将用户表的“id”字段更改为:
$table->increments("id");
我有$table->string("id")
能够自己生成ID,并且没有持久登录。