Warm tip: This article is reproduced from stackoverflow.com, please click
laravel laravel-6

How to store?

发布于 2020-04-07 10:15:15

Im trying to grab user information with this package: https://github.com/invisnik/laravel-steam-auth But im a completely noob to laravel atm.

How do I store the steamID64 in the Auth::user() field named 'steamid'

My following handling 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();
    }

I'm hoping someone can guide me in the right direction. Thanks in advance

Questioner
Kh4zy
Viewed
15
N69S 2020-02-01 17:53

You can do it using save():

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

or using update()

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

To check if the steamid already exists in your database:

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

if $isAlreadyPresent is zero then you dont have the steamid in the database or it's the current user steamid.