Last active
December 22, 2019 17:53
-
-
Save moradi-morteza/1d053d4a62a6acae371d6669cf4c794e to your computer and use it in GitHub Desktop.
[Event] #LaravelT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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