Error in customizing the default user registration Laravel Auth

Asked

Viewed 38 times

0

Error after registering and redirecting

PS: he makes the registration normally, and I can access normally, but always give this error!

inserir a descrição da imagem aqui

I made a modification only in the user register, I parameterized my relationship many to many that 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 CODE SNIPPET $this->Guard()->login($user); ** **I BELIEVE ->attach($request->company_id) is making the user give a different return than $this->Guard()->login($user); needs

2 answers

0


The function attach is returning null for the variable user.

In his job login the expected parameter shall implement the interface Authenticable which is common in the class User, to solve this create a variable with the user and do the attach without using the chained methods, see:

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

...

$this->guard()->login($user);
  • I can’t work this way you passed me because I’m in the role 'Event(new Registered( $user = $this->create($request->all())->roles()->attach(12) ); ' @rfl

  • @Gabrielalves speaks the register user outside the event and pass only the return to the class Registered.

0

IT WORKED OUT THANK YOU MT

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

    event(new Registered($user));

A doubt!! I’m using Laravel Defender but the $user->attachRole() Object Error function

  • Gabriel, regarding the error in attachRole please open another topic with your question, it may be that someone has the same problem and if your question is on another topic will be easier for everyone to find

Browser other questions tagged

You are not signed in. Login or sign up in order to post.