Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
RefreshToken
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 6
42
0.00% covered (danger)
0.00%
0 / 1
 setCustomIdAttribute
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getCustomIdAttribute
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 accessToken
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 revoke
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 transient
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getConnectionName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Models\Passport;
4
5use App\Http\Models\Moloquent;
6use App\Observers\RefreshTokenObserver;
7use Illuminate\Database\Eloquent\Attributes\ObservedBy;
8use Illuminate\Database\Eloquent\Relations\BelongsTo;
9use Laravel\Passport\Passport;
10
11#[ObservedBy([RefreshTokenObserver::class])]
12class RefreshToken extends Moloquent
13{
14    /**
15     * The database table used by the model.
16     *
17     * @var string
18     */
19    protected $table = 'oauth_refresh_tokens';
20
21    protected $fillable = ['id', 'custom_id', 'access_token_id', 'revoked', 'expires_at'];
22
23    // protected $primaryKey = 'id';
24    public $incrementing = false;
25
26    protected $keyType = 'string';
27
28    public function setCustomIdAttribute($value)
29    {
30        $this->attributes['id'] = $value;
31        $this->attributes['custom_id'] = $value;
32    }
33
34    public function getCustomIdAttribute($value = null)
35    {
36        return $this->attributes['custom_id'] ?? null;
37    }
38
39    /**
40     * The attributes that should be cast to native types.
41     *
42     * @var array
43     */
44    protected $casts = [
45        'expires_at' => 'datetime',
46        'revoked' => 'bool',
47    ];
48
49    /**
50     * Indicates if the model should be timestamped.
51     *
52     * @var bool
53     */
54    public $timestamps = false;
55
56    /**
57     * Get the access token that the refresh token belongs to.
58     */
59    public function accessToken(): BelongsTo
60    {
61        return $this->belongsTo(Passport::tokenModel());
62    }
63
64    /**
65     * Revoke the token instance.
66     */
67    public function revoke(): bool
68    {
69        return $this->forceFill(['revoked' => true])->save();
70    }
71
72    /**
73     * Determine if the token is a transient JWT token.
74     */
75    public function transient(): bool
76    {
77        return false;
78    }
79
80    /**
81     * Get the current connection name for the model.
82     */
83    public function getConnectionName(): ?string
84    {
85        return config('passport.storage.database.connection') ?? $this->connection;
86    }
87}