vendredi 21 juillet 2017

Laravel sub-auth; or sub-account selection via Guard

Firstly, I haven't coded much apps in Laravel. I have developed my app almost 90% now but I am not happy with something I have modelled as sub-accounts.

I have a User model, which hasMany Profile. When the user registers, it has no Profile. To view other parts of the app else the login/logout/register things, he must create at-least 1 profile but he may create multiple with time.

So, right now when the user tries to navigate to a page where an existing Profile is required, I have a Middleware. It intercepts, checks for if any Profile is selected (using Session). If no Profile exists, it redirects to Create Profile page. If exists but none is selected, it redirects to Select Profile page.

Is this a good approach? I really want to organise things up and try avoiding sessions for unknown reason. I never feel comfortable with hard coding session keys through-out app. Can this be implemented with a custom guard? If yes, then how should I go for it.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire