can you explain how to send a email invitation when you add a new doctor ?
How we can send an email when you create another doctor , and also how to use the verification email for every new admin
resources\views\emails\welcome.blade.php file and edit the content as you see fitphp artisan make:event DoctorCreatedphp artisan make:listener SendWelcomeEmail --event=DoctorCreated
php artisan make:mail WelcomeEmailresources\views\emails\welcome.blade.php<h1>Welcome {{$user->name}}</h1><?php
namespace App\Events;
use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class DoctorCreated
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct(
public User $user
)
{}
}<?php
namespace App\Listeners;
use App\Events\DoctorCreated;
use App\Mail\WelcomeEmail;
use Illuminate\Support\Facades\Mail;
class SendWelcomeEmail
{
/**
* Handle the event.
*/
public function handle(DoctorCreated $event): void
{
if ($event->user->role->name == 'doctor') {
Mail::to($event->user->email)->send(new WelcomeEmail($event->user));
}
}
}<?php
namespace App\Mail;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class WelcomeEmail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct(
public User $user
)
{}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
from: new Mailables\Address('admin@pet-clinic.com', 'Pet Clinic Admin'),
subject: "Welcome {$this->user->name}",
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.welcome',
);
}
}protected static function booted(): void
{
static::created(function ($user) {
event(new DoctorCreated($user));
});
}