I'm building a Laravel 4 app that requires login authentication for 3 entity types: Coach, Student & Admin, all with separate user interfaces. While I could use a package like Sentry 2 and a single DB user table with user types to achieve this, something about the potential polymorphic DB design patterns and headaches that can occur down the track, don't sit well with me. Having dealt with polymorphic issues in the past with previous apps, and the grief it can create when you want to normalise your DB structure, etc. having separate DB tables for each entity type seems a better way to go.
How would you solve this design problem?
Laravel 4 auth uses basically the following files:
- Auth.php (facade)
- AuthManager.php
- AuthServiceProvider.php
- Guard.php
- auth.php (config)
- User.php (eloquent model)
I've played around with duplicating these files to come up with mostly an independent auth for the coach entity that works, registering the facade and service provider in the app.php file, as well as making the necessary changes to config to use the Coach eloquent model for authentication:
- AuthCoach.php (facade)
- AuthCoachManager.php
- AuthCoachServiceProvider.php
- Guard.php
- authcoach.php (config)
- Coach.php (eloquent model)
I am still using Guard.php from the standard Laravel 4 auth, but Guard can easily be extended if the need arises to customise Guard methods for coach authentication by creating a GuardCoach.php file.
If I'm going to have separate auth for each entity type, do you think this is a good way to achieve it?
Can you see any potential problems or know a better way of doing this?