Php 如何修复preg_match()参数错误?

Php 如何修复preg_match()参数错误?,php,laravel,Php,Laravel,当我尝试从Steam登录到站点时,收到错误: SteamController.php第50行中的ErrorException: preg_match()要求参数2为字符串,对象为给定值 对于测试,我尝试从第50行删除代码,但什么也没发生 streamcontroller.php中的我的登录函数 public function login() { if ($this->steamAuth->validate()) { $ste

当我尝试从Steam登录到站点时,收到错误:

SteamController.php第50行中的ErrorException: preg_match()要求参数2为字符串,对象为给定值

对于测试,我尝试从第50行删除代码,但什么也没发生

streamcontroller.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();
        }
    }


为了修复错误,我需要做什么?

由于缺少信息,我假设您使用的是
invisnik/laravel steam auth
软件包来处理steam社交登录

在这种情况下,
$streaminfo
invinik\LaravelSteamAuth\streaminfo
的一个实例,它扩展了
illigate\Support\Fluent

因此,我猜
$steamInfo->getNick()
是试图检索私有
$this->attributes['nick']
属性,如果是这样,那么您的操作方式是错误的

$streaminfo->getNick()//返回对象本身。(这可能就是为什么您会得到“期望参数2是字符串,给定对象”)。
//正确的方法是:
$steamInfo->nick;
//或
$streaminfo->get('nick');

希望有帮助。

尼克的值是多少?$steamInfo->getNick()的输出是什么?$nick得到的昵称显然是一个对象。根据您传递的错误变量,它是一个对象。传递字符串是必要的。请显示
dd($nick)的输出一个错误已修复,但现在
缺少Invisnik\LaravelSteamAuth\SteamInfo::getSteamID()的参数1,在第57行调用inapp/Http/Controllers/SteamController.php,并在第57行定义了它:
'steamid'=>$SteamInfo->getSteamID(),
这意味着函数$SteamInfo->getSteamID()需要一个参数,我不知道那个论点是什么,但我认为这不是解决办法。我想这和以前的“流利”问题是一样的,看看第15行和第16行。。。该软件包为您提供了两个可供使用的属性
streamid
streamid64
$streaminfo->streamid
$streaminfo->streamid64
。希望这有帮助。@Artem,请投票,如果答案有效,请接受它。非常感谢。