Last active
March 23, 2019 17:27
-
-
Save paulund/1a0c862229c1dea9a305150cfc776d61 to your computer and use it in GitHub Desktop.
How to send an email to admin when new users sign up.
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\Mail; | |
use App\Models\User; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Mail\Mailable; | |
use Illuminate\Queue\SerializesModels; | |
class AdminNewUser extends Mailable | |
{ | |
use Queueable, SerializesModels; | |
/** | |
* @var User | |
*/ | |
private $user; | |
/** | |
* Create a new message instance. | |
* | |
* @return void | |
*/ | |
public function __construct(User $user) | |
{ | |
$this->user = $user; | |
} | |
/** | |
* Build the message. | |
* | |
* @return $this | |
*/ | |
public function build() | |
{ | |
return $this->subject('New User') | |
->markdown('mail.new-user', [ | |
'user' => $this->user | |
]); | |
} | |
} |
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\Listeners; | |
use Illuminate\Auth\Events\Registered; | |
use App\Mail\AdminNewUser; | |
use Illuminate\Support\Facades\Mail; | |
class AdminNewUserListener | |
{ | |
/** | |
* Handle the event. | |
* | |
* @param Registered $event | |
* @return void | |
*/ | |
public function handle(Registered $event) | |
{ | |
Mail::to(config('mail.from.address'))->send(new AdminNewUser($event->user)); | |
} | |
} |
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\Providers; | |
use App\Listeners\NewUser; | |
use Illuminate\Support\Facades\Event; | |
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; | |
use Illuminate\Auth\Events\Registered; | |
class EventServiceProvider extends ServiceProvider | |
{ | |
/** | |
* The event listener mappings for the application. | |
* | |
* @var array | |
*/ | |
protected $listen = [ | |
Registered::class => [ | |
SendEmailVerificationNotification::class, | |
NewUser::class | |
], | |
]; | |
/** | |
* Register any events for your application. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
parent::boot(); | |
// | |
} | |
} |
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
@component('mail::message') | |
# New User | |
A new user with email {{ $user->email }} has registered to your site. | |
@endcomponent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment