Laravel Auth Guard Users From Array

Stack Overflow Asked by GSTAR on December 18, 2020

I am building an API which will use token based authentication, I was wondering is it possible to (temporarily) use credentials from a simple predefined array of username => token?.

Here is what I have at the moment:


Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();


'guards' => [
    'api' => [
        'driver' => 'token',
        'provider' => 'users',
        'hash' => false,

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => AppModelsUser::class,

Now instead of using Eloquent, or a database, can it use a simple PHP array? So essentially I will just have something like:

$users = [
    'john' => 'token_for_john',
    'bob' => 'token_for_bob',

And then somewhere in my code I can pass in a username & token combination to authenticate? As I mentioned this is only a temporary measure before I decide on the right token based solution.

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP