0

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

Kh4zy
  • 105
  • 1
  • 3
  • 11
  • 1
    `Auth::user()->steamid = $info; Auth::user()->save();` you can also do it in one line `Auth::user()->update(['steamid' => $info]);` – N69S Jan 31 '20 at 15:54
  • @N69S Thank you so much! – Kh4zy Jan 31 '20 at 16:02
  • Is there a way to check if that is unique? As I dont want people to enter the same id, under other users. Only one allowed – Kh4zy Jan 31 '20 at 16:04

1 Answers1

1

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.

N69S
  • 16,110
  • 3
  • 22
  • 36