Enhancement Proposal: Add Morph Relationship Support to Sessions for Multiple Authenticatable Models #59547
Replies: 1 comment
-
|
Hi @eslam-reda-div, This is an interesting proposal, and I agree it highlights a real limitation when working with multi-auth setups. That said, I think this might be more of an application-level concern rather than something that needs to be handled directly by the framework. Laravel’s session table is intentionally kept simple and guard-agnostic. The framework doesn’t tie sessions to a specific authenticatable model because authentication is resolved through guards at runtime, not persisted as part of the session schema itself. In practice, most multi-auth setups handle this in one of these ways:
Introducing a polymorphic relationship ( I think your idea makes a lot of sense for applications that need advanced auditing or analytics. In those cases, extending the sessions table (or creating a custom session driver) is probably the most flexible approach without adding complexity to the framework itself. So overall:
Curious if others have taken a similar approach with custom session drivers or additional metadata on sessions. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I’d like to propose an idea that could improve how sessions are managed when working with multiple authenticatable models (e.g.,
User,Admin, etc.).Problem
Currently, the default
sessionstable structure does not provide a clear or direct way to distinguish between different types of authenticated models. For example, if an application uses bothusersandadminsguards/models, there is no built-in way to:Proposed Solution
Introduce a polymorphic (morph) relationship in the
sessionstable, such as:authenticatable_typeauthenticatable_idThis would allow each session to be directly associated with any authenticatable model using Laravel's morph relations.
Benefits
Admin::sessions())Example Use Case
Considerations
I’d love to hear your thoughts on this. Do you think this could be a valuable addition to the framework, or is there an existing approach that already solves this cleanly?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions