Events can be fired in the controller just like everything else but I believe the best place to fire events might be in the service part of the application which means inside a service class. You already have a Registar.php service class in the Services folder so fire it there.
Sending a welcome email
So I am working on my second commercial app now. My first one was Laravel 4. Was fun to build. Is awesome. However I focused more on speed while building it out. So natually it has a lot of large controllers, and doesn't really use a lot of the great features or design patters available.
So for my next app, I want to focus on the code. So right out of the gate I am spending a lot of time just thinking about structure and I have hit my first snafu. Sending registration emails.
I am using the Laravel 5 out of the box reg and login stuff which is really easy. but I would like to send some emails when users register. I feel like an event is the best way to do this so I have set up a UserWasRegistered event with a listener to NotifyNewUser, and later I will set up another listener for NotifyAdminOfNewUser. The problem is I don't know where to fire the event.
Within my UserWasRegistered event I inject the user as follows:
public function __construct(User $user)
{
$this->user = $user;
}
But given the built in Laravel 5 registration where would I put the event firing ?
event(new UserWasRegistered)
The AuthController.php uses \Illuminiate\Foundation\Auth\RegistersUsers. Obviously I don't want to put it there. What is the correct way to hook into Laravel 5's built in user registration?
Please or to participate in this conversation.