[1.x] Allow complete control of user resolution #251
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new approach for resolving users in Pulse.
There are a few scenarios we're aiming to solve here:
1. User models that don't have a
name
oremail
field, or that want to provide an alternative avatarThe most commonly needed Pulse customization is to change what fields are used to display users in the dashboard. The current approach requires you to resolve the users yourself and be sure to include an
id
field so we can map them back up again:The proposed
Pulse::user
method allows you to hook into just the field customization instead:We have maintained the existing API for backward compatibility but might propose removing it for the stable release.
2. Authenticatable classes other than
App\Models\User
orApp\User
Pulse currently checks for an
App\Models\User
orApp\User
model. With this PR, Pulse will use the configured user provider (fromconfig/auth.php
) to resolve the user. This means we'll support whichever model has been configured and will also support other user providers, such as theDatabaseUserProvider
.3. Complex authentication where the authenticable ID alone is not unique or enough to resolve the user (e.g. multi-tenancy)
Pulse currently only captures the authenticated user ID when attributing records to a user. For some applications this is not enough to uniquely resolve back to a user record for display in the dashboard.
This PR introduces a new
ResolvesUsers
contract which you can implement and bind in the service container to completely control what user identifier is captured, and how that identifier is resolved back to a user for the dashboard.The contract defines three methods required to capture and resolve users:
Fixes #121