You might repeat all of those code on your controller. The Validation, email, redirect and other similar stuff. Have you ever thought that we might create some class that might be inherited to make life easier? In laracon 2014, Jeffrey Way explain at least two ways of doing this.
1. Service Class
At this method, you might do some trick to pass the input and the reference of controller to our service class.
And, let see the content of our new class UserCreator
You also can make registrationForm (a model form) that will do validation part for you. Next, you might create interface so that the controller must implement these two methods.
2. CommandBus
Commands help you in supporting the ubiquitous languange by explicitly capturing user intent at the boundaries of your system
Jef Claes
Here we can use commandbus pattern to solve this problem
Then, let’s see our SubscribeUserCommand Class
This is pretty simple class that will receive the input. Now, let’s go to the commandbus class. The name bus because basicly it can get you to where you need to be. notice that we have one on one relationship and associative in your class.
Here is the simple command handler for subscribing user