Wednesday, March 28, 2018

Modifying Laravel’s Generated Registration Logic - development

Modifying Laravel’s Generated Registration Logic

So, I am still kind of a newbie to Laravel. As part of the application I am working on, I want to modify the registration logic generated by

php artisan make:auth

to add e-mail verification for newly registered users.

I modify the create() method on the generated RegisterController to look like this.

 protected function create(array   $data)
  {
      $user = User::create([

        'name' => $data['name'],

        'email' => $data['email'],

        'password' => Hash::make($data['password']),
    ]);

    // generate and store verification token

    $token = new Token; 
    $token->user_id = $user->id; 
    $token->token = str_randome(40); 
    $token->save(); 
    // send a verification e-mail to the 
    $this->sendVerificationEmail($user->id); 

    return $user;
}

So, on to my question. Suppose I want to capture the returned user on the verification page (which is assigned to the $redirectTo property) so that the application knows to which user to resend the e-mail if said user requests it be resent. What is the best way to achieve this?

Should I just create a new route like this

 // Routes/web.php

Route::post(‘register/{$user}’, ‘RegisterController@showConfirmation’);

And then in my RegisterController

// RegisterController
public function showConfirmation($user)
{ return view(“accountConfirmation”)->([“user”=> $user]);}

Or is there another way? I guess the route of my problem here is that I don’t quite yet understand how Laravel performs this process. But, anyways.

Thanks for the help.



from Laravel Questions and Answers https://laravelquestions.com/php/modifying-laravels-generated-registration-logic/
via Lzo Media

No comments:

Post a Comment