Created
April 2, 2019 11:02
-
-
Save akmalhazim/da66ab972f58e76bc395c52fe510d672 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
namespace App\Http\Controllers\Auth; | |
use App\Http\Controllers\Controller; | |
use App\Mail\SendUserVerificationEmail; | |
use App\UserVerification; | |
use Illuminate\Http\Request; | |
use App\User; | |
use Illuminate\Support\Facades\Mail; | |
class AuthController extends Controller | |
{ | |
public $request; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct(Request $request) | |
{ | |
$this->request = $request; | |
} | |
public function register() { | |
$this->validate($this->request, [ | |
'name' => 'required|string|max:255', | |
'email' => 'required|email|unique:users', | |
'password' => 'required|string|min:6|max:255|confirmed' | |
]); | |
app('db')->beginTransaction(); | |
$user = User::create([ | |
'name' => $this->request->input('name'), | |
'email' => $this->request->input('email'), | |
'password' => app('hash')->make($this->request->input('password')), | |
'enabled' => false | |
]); | |
// send email verification | |
$verification = UserVerification::new($user->id); | |
Mail::to($user->email)->send(new SendUserVerificationEmail($verification->unique_hash)); | |
return [ | |
'statusCode' => 4001, | |
'data' => $user | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment