1 | <?php |
||
7 | class Token extends Model |
||
8 | { |
||
9 | /** |
||
10 | * The database table used by the model. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $table = 'oauth_access_tokens'; |
||
15 | |||
16 | /** |
||
17 | * The "type" of the primary key ID. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $keyType = 'string'; |
||
22 | |||
23 | /** |
||
24 | * Indicates if the IDs are auto-incrementing. |
||
25 | * |
||
26 | * @var bool |
||
27 | */ |
||
28 | public $incrementing = false; |
||
29 | |||
30 | /** |
||
31 | * The guarded attributes on the model. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $guarded = []; |
||
36 | |||
37 | /** |
||
38 | * The attributes that should be cast to native types. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $casts = [ |
||
43 | 'scopes' => 'array', |
||
44 | 'revoked' => 'bool', |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * The attributes that should be mutated to dates. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $dates = [ |
||
53 | 'expires_at', |
||
54 | ]; |
||
55 | |||
56 | /** |
||
57 | * Indicates if the model should be timestamped. |
||
58 | * |
||
59 | * @var bool |
||
60 | */ |
||
61 | public $timestamps = false; |
||
62 | |||
63 | /** |
||
64 | * Get the client that the token belongs to. |
||
65 | * |
||
66 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
67 | */ |
||
68 | public function client() |
||
72 | |||
73 | /** |
||
74 | * Get the user that the token belongs to. |
||
75 | * |
||
76 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
77 | */ |
||
78 | public function user() |
||
84 | |||
85 | /** |
||
86 | * Determine if the token has a given scope. |
||
87 | * |
||
88 | * @param string $scope |
||
89 | * |
||
90 | * @return bool |
||
91 | */ |
||
92 | public function can($scope) |
||
110 | |||
111 | /** |
||
112 | * Resolve all possible scopes. |
||
113 | * |
||
114 | * @param string $scope |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | protected function resolveInheritedScopes($scope) |
||
130 | |||
131 | /** |
||
132 | * Determine if the token is missing a given scope. |
||
133 | * |
||
134 | * @param string $scope |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | public function cant($scope) |
||
142 | |||
143 | /** |
||
144 | * Revoke the token instance. |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function revoke() |
||
152 | |||
153 | /** |
||
154 | * Determine if the token is a transient JWT token. |
||
155 | * |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function transient() |
||
162 | } |
||
163 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: