Kirk Olson
Kirk Olson

Reputation: 564

Change Laravel TokenGuard storagekey

I'm trying to implement the new Laravel 5.3 auth:api middleware using api tokens. Since I already have a legacy users table containing an 'ApiToken' field I would like to change the TokenGuard storageKey property (and possibly also the inputKey) to "ApiToken" instead of 'api_token'. Similar to the getRememberTokenName method, I couldn't find a 'getApiTokenName' method however. Is there a way to accomplish this without altering the Laravel TokenGuard source?

Upvotes: 3

Views: 717

Answers (1)

Paul Androschuk
Paul Androschuk

Reputation: 796

You cannot override the storageKey in TokenGuard class. But you have 2 options to solve your problem:

  1. Create your custom guard which should be extended from TokenGuard and inside it change the 'storageKey' property. And then register your custom guard inside AuthServiceProvider as your guard and use them.

  2. Change 'ApiToken' field in your table to snake_case.

Upvotes: 3

Related Questions