Commit 2c82b1c
Fix »OAuth Client Table Changes« migration snippet in the upgrade guide (#1859)
* Fix owner columns are not added after the `user_id` as intended
* Fix `TypeError` when migrating the `oauth_clients` table
TypeError
Laravel\Passport\Client::{closure:Laravel\Passport\Client::grantTypes():157}(): Return value must be of type array, null returned
This happens because `isset($value) ? $this->fromJson($value) : array_keys(/* … */)` evaluates to `null`.
> After adding a non-nullable `grant_types` column with no default values `isset($value)` is `true` because `$value` is an empty string.
> As a result `$this->fromJson($value)` is called with an empty string which evaluates to `null` …
```php
> $value = ''; isset($value);
= true
```
This then violates the return type `get: fn (?string $value): array` …
Making the field nullable first fixes the issue:
```php
> $value = null; isset($value);
= false
```
Once the data is written I set nullable to false because the original migration creates a non-nullable field as well …
An alternative to this "workaround" would be updating the `Laravel\Passport\Client::grantTypes()` implementation.
* Fix broken polymorphic owner relationship
The `config()` call falls back to `null` when the `$client` has on provider.
The result is a client with an `owner_id` that has no corresponding `owner_type` set.
Adding `\App\Models\User::class` as a fallback seems reasonable.
* Replace hardcoded User class-string
Co-authored-by: Hafez Divandari <[email protected]>
* Leave `grant_types` nullable.
---------
Co-authored-by: Hafez Divandari <[email protected]>1 parent 36af05a commit 2c82b1c
1 file changed
+5
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
144 | | - | |
| 142 | + | |
145 | 143 | | |
146 | 144 | | |
147 | 145 | | |
148 | | - | |
| 146 | + | |
149 | 147 | | |
150 | 148 | | |
151 | 149 | | |
152 | 150 | | |
153 | 151 | | |
154 | 152 | | |
155 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
0 commit comments