Error in customizing the default user registry Laravel Auth

1

Error after registering and redirecting

PS: it does the registration normally, and I can access normally, but this error always!

I MAKE A MODIFICATION ONLY IN THE USER REGISTRATION, MAKE THE PARAMETERIZATION OF MY MANY TO MANY RELATIONSHIP WHICH ALSO WORKS

 public function register(Request $request)
{

    $this->validator($request->all())->validate();

    event(new Registered(
        $user = $this->create($request->all())->companies()->attach($request->company_id)


    ));

    $this->guard()->login($user);

    return $this->registered($request, $user)
                    ?: redirect($this->redirectPath());
}

The ERROR IS IN THIS SECTION OF THE CODE $ this-> gt; () - > login ($ user); ** ** I BELIEVE that - > attach ($ request-> company_id) is giving the user a different return than the $ this- > login ($ user); accurate

    
asked by anonymous 08.03.2018 / 13:26

2 answers

1

The attach function is returning null to the user variable.

In its login function, the expected parameter must implement the Authenticable interface that is common in the User class. To solve this, create a variable with the user and make the attach without using the chained methods, see :

$user = $this->create($request->all());
$user->companies()->attach($request->company_id);

...

$this->guard()->login($user);
    
08.03.2018 / 14:04
0

DEU CERTO MT THANK YOU

$user = $this->create($request->all());
    $user->roles()->attach(12);
    $user->companies()->attach($request->company_id);

    event(new Registered($user));

A question !! I'm using Laravel Defender but the function $ user-> attachRole () of Object Error

    
08.03.2018 / 14:24