-
模型程式碼
<?php namespace App\Http\Models\Api\Server; use Auth; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; use Spatie\Permission\Models\Permission; use Spatie\Permission\Traits\HasRoles; use Tymon\JWTAuth\Contracts\JWTSubject; class Servers extends Authenticatable implements JWTSubject { use HasRoles; protected $guard_name = 'server'; public function __construct() { if (!cache()->has('hasPermission_server_manage_user')) { if (Permission::findOrCreate(0,'server_manage_user', '管理使用者')) { cache()->set('hasPermission_server_manage_user', 1, 60 * 60 * 24); } } } public function getJWTIdentifier() { return $this->getKey(); }
-執行後資料庫中
-
config/auth.php
'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],'user' => [ 'driver' => 'jwt', 'provider' => 'users', ], 'server' => [ 'driver' => 'jwt', 'provider' => 'servers', ],
],
有大佬能指點下嗎?