I'm reading through a lot of guides, tutorials on MVC and Laravel. Simple example, handling user registration. The majority of them suggest the something like the following:
User Model:
Attributes: id, name, email, password
UserController:
Method getRegister() // Show registration form
Method postRegister()
Further detail in postRegister() method of UserController
- Gather User input
- Validate against model
- If fails, return to getRegister() with errors
- If passes, try to register user (Hash password, use ORM to insert user to database)
- If fails, return exception and redirect to appropriate page.
- If passes, return success and redirect to appropriate page.
Example implementation: https://github.com/rydurham/L4withSentry
In this implementation, the Model is simply being used as an interface to the ORM, nothing more.
The Question:
Now I am not knocking the implementation posted above, because it shows a really good working example of how Cartalyst Sentry works... However, is this the best/appropriate way of registering the user?
Should the whole validation / hashing / registering etc... not be performed within the model? Then the model return success or failure to the Controller to act appropriately?
If you take a look at the UserController app/controllers/UserController.php, this is extremely Fat, whilst the User model app/models/User.php is very skinny.
e.g. Should the User model not have a registerUser() method which would perform most of the registration process?
At present, a user can register themselves, or an admin user would be able to register a user. As such, a bulk of controller code would need to be repeated for admin/user/register and login/register
If I am correct in my thoughts, can anybody point me in the direction of potentially Fat Model, Skinny Controller implementation so that I can understand more how they work?