-
app/Http/Controllers/ApiRegisterController.php
Open in GitHubuse App\Events\UserSignedUp; use Illuminate\Support\Facades\Mail; use Illuminate\Auth\Events\Registered; class ApiRegisterController extends Controller { public function register (Request $request) { $this->validate($request, [ 'email' => 'required|email|max:75|unique:users', 'password' => 'required|min:6|max:255', //case_diff|numbers|letters 'username' => 'required|unique:users' ]); $email = $request->email; event(new Registered($user = $this->create($request->all()))); if (app()->environment('production')) { Mail::to($email)->send(new NewUserRegMail($user)); event(new UserSignedUp(now())); } return ['success' => 'Success! Your account has been created.']; } // }
-
app/Mail/NewUserRegMail.php
Open in GitHubuse App\Models\User\User; use Illuminate\Mail\Mailable; class NewUserRegMail extends Mailable { public $user; public function __construct($user) { $this->user = $user; } public function build() { // return $this->view('view.name'); return $this->from('welcome@openlittermap.com') ->subject('Register your email for Open Litter Map') ->view('auth.emails.confirm') ->with([ 'token' => $this->user->token ]); } }