'Clients authentication and user authentication with laravel

I am working on api, where I have the following models.

Merchant -> hasMany -> Shops
Shop -> hasMany -> Customers

Each merchant will have api tokens in order to connect his apps with the api, but also i want to provide authentication for the customers.

I know that I can achieve the clients (Merchant) authentication on api with the laravel passport, but what about the customers authentication?



Solution 1:[1]

If you want to use different authentication then you can create custom Provider and custom Guard in auth.php

Add Guard For Customer in auth.php

 'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users'
        // 'hash' => false,
    ],

    // Guard For Customer 

     'custome_api' => [
        'driver' => 'passport',
        'provider' => 'customers'
    ],
],

Here Customers Provider Added for customer in auth.api

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
    ],

     'customers' => [
        'driver' => 'eloquent',
       'model' => App\Models\Customer::class,
    ],
],

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Harsh vaghasiya