1 | <?php |
||
12 | class ApiCredential extends Model |
||
13 | { |
||
14 | use SoftDeletes; |
||
15 | use HasFactory; |
||
16 | use WithSearchableEncryptedAttribute; |
||
17 | |||
18 | protected $guarded = []; |
||
19 | |||
20 | protected $table = 'key_api_credentials'; |
||
21 | |||
22 | /** |
||
23 | * Statues for api credential. |
||
24 | */ |
||
25 | public const STATUSES = [ |
||
26 | 'ACTIVE' => 'active', |
||
27 | 'SUSPENDED' => 'suspended', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Public key prefix. |
||
32 | */ |
||
33 | public const PUBLIC_KEY_PREFIX = 'api_key_pub'; |
||
34 | |||
35 | /** |
||
36 | * Private key prefix. |
||
37 | */ |
||
38 | public const PRIVATE_KEY_PREFIX = 'api_key_prv'; |
||
39 | |||
40 | /** |
||
41 | * The hidden columns. |
||
42 | * |
||
43 | * @var string[] |
||
44 | */ |
||
45 | protected $hidden = [ |
||
46 | 'secret_hash', 'deleted_at', |
||
47 | ]; |
||
48 | |||
49 | /** |
||
50 | * The encrypted field or column. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $encrypted = 'private_key'; |
||
55 | |||
56 | /** |
||
57 | * The blind index field or column. |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $blindIndex = 'secret_hash'; |
||
62 | |||
63 | /** |
||
64 | * Get the client for the api key. |
||
65 | * |
||
66 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
67 | */ |
||
68 | public function client(): BelongsTo |
||
72 | |||
73 | /** |
||
74 | * Sets the value for private key column. |
||
75 | * |
||
76 | * @param string $key |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | public function setPrivateKeyAttribute(string $key): void |
||
84 | |||
85 | /** |
||
86 | * Sets the value secret hash column. |
||
87 | * |
||
88 | * @param string|null $hash |
||
89 | * |
||
90 | * @throws \ParagonIE\CipherSweet\Exception\BlindIndexNotFoundException |
||
91 | * @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException |
||
92 | * @throws \SodiumException |
||
93 | * |
||
94 | * @return void |
||
95 | */ |
||
96 | public function setSecretHashAttribute(?string $hash = null): void |
||
100 | |||
101 | /** |
||
102 | * Get the value for private key column. |
||
103 | * |
||
104 | * @param string $encryptedKey |
||
105 | * |
||
106 | * @return mixed |
||
107 | */ |
||
108 | public function getPrivateKeyAttribute(string $encryptedKey) |
||
112 | |||
113 | /** |
||
114 | * Add where clause for status equals active. |
||
115 | * |
||
116 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
117 | * |
||
118 | * @return \Illuminate\Database\Eloquent\Builder |
||
119 | */ |
||
120 | public function scopeActive(Builder $query): Builder |
||
124 | |||
125 | /** |
||
126 | * Add where clause for status equals active. |
||
127 | * |
||
128 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
129 | * |
||
130 | * @return \Illuminate\Database\Eloquent\Builder |
||
131 | */ |
||
132 | public function scopeSuspended(Builder $query): Builder |
||
136 | |||
137 | /** |
||
138 | * Find client active api keys by private key. |
||
139 | * |
||
140 | * @param string $privateKey |
||
141 | * |
||
142 | * @return static|null |
||
143 | */ |
||
144 | public static function findActiveByPrivateKey(string $privateKey): ?self |
||
152 | |||
153 | /** |
||
154 | * Find client suspended api keys by private key. |
||
155 | * |
||
156 | * @param string $privateKey |
||
157 | * |
||
158 | * @return static|null |
||
159 | */ |
||
160 | public static function findSuspendedByPrivateKey(string $privateKey): ?self |
||
168 | |||
169 | /** |
||
170 | * Find client api keys by private key. |
||
171 | * |
||
172 | * @param string $privateKey |
||
173 | * |
||
174 | * @return static|null |
||
175 | */ |
||
176 | public static function findByPrivateKey(string $privateKey): ?self |
||
183 | |||
184 | /** |
||
185 | * Generates the public and secret key pairs for both live and test domains. |
||
186 | * @throws \Exception |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | public static function generateKeyPairArray(): array |
||
201 | |||
202 | /** |
||
203 | * Generate unique public and secret key pairs. |
||
204 | * @throws \Exception |
||
205 | * |
||
206 | * @return array |
||
207 | */ |
||
208 | private static function generatePublicPrivateKeys(): array |
||
220 | } |
||
221 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: