Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify PersonalAccessToken Model to be polymorphic #49

Merged

Conversation

amaelftah
Copy link
Contributor

this PR resolves #10 .

by making PersonalAccessToken model polymorphic will allow multiple models to be authenticated through airlock tokens .

for example if i have Pharmacist & Doctor models . and would authenticate both of them through api . i would have to implement this solution which is in my opinion a little bit tedious .

but by making PersonalAccessToken model polymorphic. this will allow implementing the above use case without any extra boilerplate .

and also customization to user Model through userModel() won't be needed any more . cause polymorphic relation will support any other models .

@taylorotwell
Copy link
Member

taylorotwell commented Jan 20, 2020

I think I would suggest renaming even the user relationship on the model to something like tokenable and then having tokenable_id and tokenable_type as the morph columns.

@amaelftah
Copy link
Contributor Author

@taylorotwell Done . and i thnk you are right since the token now belongs to multiple different models .

@taylorotwell taylorotwell merged commit 95f3761 into laravel:master Jan 20, 2020
@rgr
Copy link

rgr commented Jan 7, 2021

Is there a way to use sanctum without morphing features to save database space and keep a basic user_id column ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use polymorphic relationship
3 participants