首页 > 解决方案 > Laravel 6 steam auth - 如何存储?

问题描述

我试图用这个包获取用户信息:https ://github.com/invisnik/laravel-steam-auth 但我对 laravel atm 完全是个菜鸟。

如何将 steamID64 存储在名为“steamid”的 Auth::user() 字段中

我的以下处理atm:

public function handle()
    {
        if ($this->steam->validate()) {
            $info = $this->steam->getSteamId();

            if (!is_null($info)) {
                //I should store the steamid64 inside the Auth::user() field named 'steamid'
                return redirect($this->redirectURL); // redirect to site
            }
        }
        return $this->redirectToSteam();
    }

我希望有人能引导我朝着正确的方向前进。提前致谢

标签: laravellaravel-6

解决方案


您可以使用save()

Auth::user()->steamid = $info;
Auth::user()->save();

或使用update()

Auth::user()->update(['steamid' => $info]);

要检查您的数据库中是否已存在 steamid:

$isAlreadyPresent = User::where('id', '!=', Auth::id())->where('steamid', '=', $info)->count();

如果$isAlreadyPresent为零,那么您在数据库中没有 steamid,或者它是当前用户的 steamid。


推荐阅读