Skip to content

Instantly share code, notes, and snippets.

@moradi-morteza
Last active December 22, 2019 17:53
Show Gist options
  • Save moradi-morteza/1d053d4a62a6acae371d6669cf4c794e to your computer and use it in GitHub Desktop.
Save moradi-morteza/1d053d4a62a6acae371d6669cf4c794e to your computer and use it in GitHub Desktop.
[Event] #LaravelT
php artisan make:event RegisterUser // this event actioned
// in class EventServiceProvider
protected $listen =[
Registered::class=>[
SendEmailVerificationNotification::class,
],
RegisterUser::class=>[
// the listener that figour out event runned
//your custom listener
'\App\Listeners\SendVerificationCodeEmail',
'\App\Listeners\SendWelcomeEmail'
]
]
php artisan event:generate // this create SendVerificationCodeEmail
// for call event
event(new RegisterUser($user));
// in __construct(User $user) in RegisterUser
// in handle function in SendVerificationCodeEmail define your action
//----- RegisterUser.php
public $user;
public funtion getUser(){
return $this->user;}
public funtion __construct(User $user){
$this->user=$user;
}
//----- SendVerificationCodeEmail.php
pubic function handle (RegisterUser $event){
$user=$event->getUser();
// do more ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment