Last active
May 3, 2017 00:00
-
-
Save introwit/f0ade18cbad47288350129654ded9ae8 to your computer and use it in GitHub Desktop.
Email verification blog - gist 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Over-ridden the register method from the "RegistersUsers" trait | |
* Remember to take care while upgrading laravel | |
*/ | |
public function register(Request $request) | |
{ | |
// Laravel validation | |
$validator = $this->validator($request->all()); | |
if ($validator->fails()) | |
{ | |
$this->throwValidationException($request, $validator); | |
} | |
// Using database transactions is useful here because stuff happening is actually a transaction | |
// I don't know what I said in the last line! Weird! | |
DB::beginTransaction(); | |
try | |
{ | |
$user = $this->create($request->all()); | |
// After creating the user send an email with the random token generated in the create method above | |
$email = new EmailVerification(new User(['email_token' => $user->email_token, 'name' => $user->name])); | |
Mail::to($user->email)->send($email); | |
DB::commit(); | |
return back(); | |
} | |
catch(Exception $e) | |
{ | |
DB::rollback(); | |
return back(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment