این ارور رو بر می گردونه :
Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Argument 1 passed to App\Listeners\UserActivation\SendMailNotification::handle() must be an instance of App\Events\UserActivation, instance of Illuminate\Auth\Events\Registered given"
که مربوط به این کد میشه :
class SendMailNotification
{
/**
* Create the event listener.
*
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UserActivation|object $event
* @return void
*/
public function handle(UserActivation $event)
{
Mail::to($event->user)->send(new ActivationUserAccount($event->user, $event->activationCode));
}
} ```
سلام
@myzerone2
وقتی شما دارید از ActivationUserAccount
یک شی میسازید
توی همین صفحه ای که هستید روی همین واژه ActivationUserAccount
Ctrl + Enter بزنید تا اسم کلاسش توی همین صفحه use بشه
یه نمونه
<?php
namespace App\Listeners\EventListener\Auth;
use App\Events\Auth\ResetPasswordPin as ResetPasswordPinEvent;
use App\Notifications\System;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class ResetPasswordPin
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param ResetPasswordPinEvent $event
* @return void
*/
public function handle(ResetPasswordPinEvent $event)
{
$event->user->notify(new System(trans('passwords.recovery'),trans('passwords.change')));
}
}
System رو ببینید اون بالا
همچین چیزی :
use AppNotificationsSystem;
استفاده شده
شما هم برای اون یعنی : ActivationUserAccount
نیم اسپیسش که در چه مسیری هست رو use کنید!
آقا من جمله رو بد خوندم. name sapce رو با نیم اسپیس یا همون نیم فاصله اشتباه گرفتم. حرفتون درسته. alt + enterرو زدم و useشدن. ولی باز هم خطا دارن. چیزی که اعلام میشه بابت خطا مربوطه به handle() هست.
این کد listener
<?php
namespace App\Listeners\UserActivation;
use App\Events\UserActivation;
use App\Mail\ActivationUserAccount;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Mail;
class SendMailNotification
{
/**
* Create the event listener.
*
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UserActivation $event
* @return void
*/
public function handle(UserActivation $event)
{
Mail::to($event->user)->send(new ActivationUserAccount($event->user, $event->activationCode));
}
}
این کد event
<?php
namespace App\Events;
use App\ActivationCode;
use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class UserActivation
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
public $activationCode;
/**
* Create a new event instance.
* @param User $user
*/
public function __construct( User $user)
{
$this->user = $user;
$this->activationCode = ActivationCode::createCode($user)->code;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
این کد رجیستر
<?php
namespace App\Http\Controllers\Auth;
use App\Events\UserActivation;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Registered;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
/**
* Handle a registration request for the application.
*
* @param Request|\Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
event(new UserActivation($request->all()));
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
}
وقتی این کد رو حذف می کنم، عملیات انجام می شه ولی ایمیل ارسال نمیشه. وقتی هم که هست ارور میده
event(new Registered($user = $this->create($request->all())));
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟