PHP code example of osi / auth-api

1. Go to this page and download the library: Download osi/auth-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

osi / auth-api example snippets


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

        // ** New provider**
        'admin-api' => [
            'driver' => 'eloquent',
            'model' => Osi\AuthApi\Models\Admin::class,
        ],
    ],
    // ...

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

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
            'hash' => false,
        ],
	    // ** New guard **
        'admin-api' => [
            'driver' => 'sanctum',
            'provider' => 'admin-api',
            'name' => 'Admin`s Api',
        ],
    ],

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Laravel\Sanctum\HasApiTokens;
use Osi\AuthApi\Models\AuthInterface;
class Admin extends Authenticatable implements AuthInterface
{
    use HasApiTokens;
    public function resourceFormat()
    {
    	return $this;
    	// OR Create New Resource
        // return new AuthResource($this);
    }
    public function findForPassport($username)
    {
        return $this->where('username', $username)->first();
    }
    public function apiLogs(): MorphMany
    {
       // return $this->morphMany(ApiLog::class, 'model');
    }
    public function apiPermissions(): MorphMany
    {
       // return $this->morphMany(ApiPermission::class, 'model');
    }
}