appserviceprovider.php>
Код: Выделить всё
use App\Events\Frontend\OTPVerificationEvent;
use App\Listeners\Frontend\{OTPOnMobileListener, OTPOnWhatsappListener};
class AppServiceProvider extends ServiceProvider {
...
/**
* Bootstrap any application services.
*/
public function boot(): void {
Event::listen(OTPVerificationEvent::class, [
[new OTPOnMobileListener, 'handle'],
[new OTPOnWhatsappListener, 'handle'],
]);
// --- OR ---
Event::listen(OTPVerificationEvent::class, [
new OTPOnMobileListener,
new OTPOnWhatsappListener,
]);
// --- OR ---
Event::listen(OTPVerificationEvent::class, [
OTPOnMobileListener::class,
OTPOnWhatsappListener::class,
]);
}
}
Код: Выделить всё
class OTPVerificationEvent {
/**
* Public variables
*/
public $mobile;
public $mobileOtp;
public $whatsappOtp;
/**
* Create a new event instance.
*/
public function __construct($mobile, $mobileOtp, $whatsappOtp) {
$this->mobile = $mobile;
$this->mobileOtp = $mobileOtp;
$this->whatsappOtp = $whatsappOtp;
}
/**
* Get the channels the event should broadcast on.
*
* @return array
*/
public function broadcastOn(): array {
return [
// new PrivateChannel('channel-name'),
];
}
}
Код: Выделить всё
class OTPOnMobileListener {
/**
* Handle the event.
*/
public function handle(object $event): void {
echo "";
print_r($event);
echo "\n";
exit;
}
}
Код: Выделить всё
class OTPOnWhatsappListener {
/**
* Handle the event.
*/
public function handle(object $event): void {
echo "";
print_r($event);
echo "\n";
exit;
}
}
Первый массив.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... e-or-objec
Мобильная версия