64 lines
1.3 KiB
PHP
64 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\{Builder, Model};
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property string $provider
|
|
* @property string $access_token
|
|
* @property string|null $refresh_token
|
|
* @property string $token_type
|
|
* @property string|null $scopes
|
|
* @property \Illuminate\Support\Carbon $expires_at
|
|
*/
|
|
class OauthToken extends Model
|
|
{
|
|
protected $table = 'oauth_tokens';
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'provider',
|
|
'access_token',
|
|
'refresh_token',
|
|
'token_type',
|
|
'scopes',
|
|
'expires_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'expires_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function isExpired(): bool
|
|
{
|
|
return $this->expires_at->isPast();
|
|
}
|
|
|
|
/**
|
|
* @param Builder<OauthToken> $query
|
|
*
|
|
* @return Builder<OauthToken>
|
|
*/
|
|
public function scopeForProvider(Builder $query, string $provider): Builder
|
|
{
|
|
return $query->where('provider', $provider);
|
|
}
|
|
}
|