当我尝试从Steam登录到站点时,收到错误消息:
SteamController.php第50行中的ErrorException: preg_match()期望参数2为字符串,给定对象
为了测试,我尝试从第50行删除代码,但是什么也没发生。
我在SteamController.php中的登录功能
public function login()
{
if ($this->steamAuth->validate()) {
$steamID = $this->steamAuth->getSteamId();
$user = User::where('steamid64', $steamID)->first();
if (!is_null($user)) {
$steamInfo = $this->steamAuth->getUserInfo();
$nick = $steamInfo->getNick();
if (preg_match("/Admin|admins|admin|/i", $nick)) {
$nick = 'ADmin';
}
\DB::table('users')->where('steamid64', $steamID)->update(['username' => $nick, 'avatar' => $steamInfo->getProfilePictureFull()]);
if ($user->partner == 0) {
\DB::table('users')->where('steamid64', $steamID)->update(['partner' => \Request::cookie('ref')]);
}
} else {
$steamInfo = $this->steamAuth->getUserInfo();
$nick = $steamInfo->getNick();
if (preg_match("/|Admin|admins|admin/i", $nick)) {
$nick = 'Admin';
}
$user = User::create([
'username' => $nick,
'avatar' => $steamInfo->getProfilePictureFull(),
'steamid' => $steamInfo->getSteamID(),
'steamid64' => $steamInfo->getSteamID64(),
'partner' => \Request::cookie('ref')
]);
}
Auth::login($user, true);
return redirect('/');
} else {
return $this->steamAuth->redirect();
}
}
要解决错误,我该怎么办?
答案 0 :(得分:1)
由于缺乏信息,我假设您正在使用invisnik/laravel-steam-auth
软件包来处理Steam社交登录。
在这种情况下,$steamInfo
是Invisnik\LaravelSteamAuth\SteamInfo
的实例,扩展了Illuminate\Support\Fluent
。
因此,我猜想$steamInfo->getNick()
是一种尝试检索私有$this->attributes['nick']
属性的尝试,如果是这种情况,那么您做错了方法。
$steamInfo->getNick() // returns itself, an object. (Thats probably why you're getting "expects parameter 2 to be string, object given").
// The correct way:
$steamInfo->nick;
// or
$steamInfo->get('nick');
希望有帮助。