Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

php - how to change api_token column in token guard

Laravel 5.5

I want to change direction of api token that used in TokenGaurd so, i created a custom guard named CafeTokenGaurd extends TokenGuard, i define __construct function into it like what i want, something like this:

public function __construct(UserProvider $provider, Request $request) {
        parent::__construct($provider, $request);
        $this->inputKey = 'api_key'; // I want changing this part
        $this->storageKey = 'api_key';
    }

Now i want to define api_key from relation with users table like this:

device_user table -> token

i want to define specific tokens for each devices user have, and i want to set api key input and storage key to this column in pivot table between users and devices,

how i should this?!

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since the version Laravel 5.7.28, You can simply set up in config/auth.php.

'guards' => [
    'api' => [
        'driver' => 'token',
        'input_key' => 'token',   // The input name to pass through
        'storage_key' => 'token', // The column name to store in database
        'provider' => 'users',
    ],
],

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...