0
votes

My registration form additionally accepts the name of the user's company, which I want to insert in a separate table "Holdings". All data is successfully saved to the Holdings and Users table, but an error occurs at the last step when redirecting to the home page.

ResgisterController:

protected function create(array $data)
    {

        //Mail::to($data['email'])->send(new Welcome($data['name']));


        $id = User::insertGetId([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'role' => 8
        ]);

        $oHolding = new Holdings;
        $oHolding->shortname = $data['orgname'];
        $oHolding->creator = $id;
        $oHolding->save();

        DB::table('users')->where('id', $id)->update([
            'holding_id' => $oHolding->id,
        ]);

        $user = DB::table('users')->select('*')->where('id', $id)->get();

        return $user;
    }

Error Message:

Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Support\Collection given, called in /Users/admin/Sites/jetime/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php on line 35

Login Function

public function login(AuthenticatableContract $user, $remember = false)
    {
        $this->updateSession($user->getAuthIdentifier());

        // If the user should be permanently "remembered" by the application we will
        // queue a permanent cookie that contains the encrypted copy of the user
        // identifier. We will then decrypt this later to retrieve the users.
        if ($remember) {
            $this->ensureRememberTokenIsSet($user);

            $this->queueRecallerCookie($user);
        }

        // If we have an event dispatcher instance set we will fire an event so that
        // any listeners will hook into the authentication events and run actions
        // based on the login and logout events fired from the guard instances.
        $this->fireLoginEvent($user, $remember);

        $this->setUser($user);
    }

I will be glad of any help, how to fix the error?

1
change protected function create(array $data) to protected function create($data)sta
where is the login function?Giacomo M
@GiacomoM Hello! added to the questionAlexander Schurf

1 Answers

0
votes

You are returning a collection rather than an instance of a class that implements Authenticatable.

You can see this happening here:

$user = DB::table('users')->select('*')->where('id', $id)->get();

return $user;

If you have the User model that ships with Laravel, then you'll actually want to do:

$user = User::find($id);

return $user;

Although your whole create method could be cleaned up to streamline all of this, however that isn't the topic of your question.