Merhaba,
Laravel 10 üzerinde çalışıyorum. Fortify kullanıyorum. Kullanıcı kayıt olduğunda mail göndermesini istiyorum ancak şöyle bir hata alıyorum: Unresolvable dependency resolving [Parameter #0 [ <required> $user ]] in class Illuminate\Auth\Events\Registered
EventServiceProvider
<?php
namespace App\Providers;
use App\Listeners\SendWelcomeEmail;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
SendWelcomeEmail::class,
],
];
/**
* Register any events for your application.
*/
public function boot(): void
{
}
/**
* Determine if events and listeners should be automatically discovered.
*/
public function shouldDiscoverEvents(): bool
{
return false;
}
}
SendWelcomeEmail // Listener
<?php
namespace App\Listeners;
use App\Mail\WelcomeEmail;
use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Log;
class SendWelcomeEmail implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(Registered $event)
{
//
}
/**
* Handle the event.
*/
public function handle(Registered $event): void
{
Mail::to($event->user->email)->send(new WelcomeEmail($event->user));
}
}
WelcomeEmail // Mail
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use App\Models\User;
class WelcomeEmail extends Mailable
{
public $user;
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Hoş geldiniz!',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.welcome',
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
Mail blade şablonu:
<!DOCTYPE html>
<html>
<head>
<title>Hoş Geldiniz!</title>
</head>
<body>
<h1>Merhaba, {{ $user->email }}!</h1>
<p>Başarıyla kayıt oldunuz. Hoş geldiniz.</p>
</body>
</html>