-
app/Mail/UserCreated.php
Open in GitHubuse Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; class UserCreated extends Mailable implements ShouldQueue { use Queueable; use SerializesModels; public string $login; public string $password; public $url; public function __construct($login, $password) { $this->login = $login; $this->password = $password; $this->url = config('app.frontend_url'); } public function build(): self { return $this->markdown('emails.invite'); } }
-
app/Observers/UserObserver.php
Open in GitHubuse App\Mail\UserCreated; use App\Models\User; use Mail; use Illuminate\Support\Str; use Settings; class UserObserver { public function creating(User $user): void { if (!$user->password || request('send_invite')) { $password = request('password') ?? Str::random(); $user->password = $password; $user->invitation_sent = true; $language = Settings::scope('core')->get('language', 'en'); Mail::to($user->email)->locale($language)->send(new UserCreated($user->email, $password)); } } }