Skip to content

Commit 1e3ebb3

Browse files
[13.x] Use unique IDs on client model (#1757)
* [13.x] Use unique ids on client model * drop support for Laravel 9.x * wip
1 parent 1cf9234 commit 1e3ebb3

File tree

5 files changed

+43
-39
lines changed

5 files changed

+43
-39
lines changed

.github/workflows/tests.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ jobs:
1717
fail-fast: true
1818
matrix:
1919
php: [8.1, 8.2, 8.3]
20-
laravel: [9, 10, 11]
20+
laravel: [10, 11]
2121
exclude:
2222
- php: 8.1
2323
laravel: 11
24-
- php: 8.3
25-
laravel: 9
2624

2725
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
2826

UPGRADE.md

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ PR: https://github.com/laravel/passport/pull/1734
1010

1111
PHP 8.1 is now the minimum required version.
1212

13+
### Minimum Laravel Version
14+
15+
PR: https://github.com/laravel/passport/pull/1757
16+
17+
Laravel 10.0 is now the minimum required version.
18+
1319
### OAuth2 Server
1420

1521
PR: https://github.com/laravel/passport/pull/1734

composer.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
"ext-json": "*",
1919
"ext-openssl": "*",
2020
"firebase/php-jwt": "^6.4",
21-
"illuminate/auth": "^9.21|^10.0|^11.0",
22-
"illuminate/console": "^9.21|^10.0|^11.0",
23-
"illuminate/container": "^9.21|^10.0|^11.0",
24-
"illuminate/contracts": "^9.21|^10.0|^11.0",
25-
"illuminate/cookie": "^9.21|^10.0|^11.0",
26-
"illuminate/database": "^9.21|^10.0|^11.0",
27-
"illuminate/encryption": "^9.21|^10.0|^11.0",
28-
"illuminate/http": "^9.21|^10.0|^11.0",
29-
"illuminate/support": "^9.21|^10.0|^11.0",
21+
"illuminate/auth": "^10.0|^11.0",
22+
"illuminate/console": "^10.0|^11.0",
23+
"illuminate/container": "^10.0|^11.0",
24+
"illuminate/contracts": "^10.0|^11.0",
25+
"illuminate/cookie": "^10.0|^11.0",
26+
"illuminate/database": "^10.0|^11.0",
27+
"illuminate/encryption": "^10.0|^11.0",
28+
"illuminate/http": "^10.0|^11.0",
29+
"illuminate/support": "^10.0|^11.0",
3030
"lcobucci/jwt": "^5.0",
3131
"league/oauth2-server": "^9.0",
3232
"nyholm/psr7": "^1.5",

database/factories/ClientFactory.php

+2-19
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,15 @@ public function modelName()
2828
*/
2929
public function definition()
3030
{
31-
return $this->ensurePrimaryKeyIsSet([
31+
return [
3232
'user_id' => null,
3333
'name' => $this->faker->company(),
3434
'secret' => Str::random(40),
3535
'redirect' => $this->faker->url(),
3636
'personal_access_client' => false,
3737
'password_client' => false,
3838
'revoked' => false,
39-
]);
40-
}
41-
42-
/**
43-
* Ensure the primary key is set on the model when using UUIDs.
44-
*
45-
* @param array $data
46-
* @return array
47-
*/
48-
protected function ensurePrimaryKeyIsSet(array $data)
49-
{
50-
if (Passport::clientUuids()) {
51-
$keyName = (new ($this->modelName()))->getKeyName();
52-
53-
$data[$keyName] = (string) Str::orderedUuid();
54-
}
55-
56-
return $data;
39+
];
5740
}
5841

5942
/**

src/Client.php

+25-8
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,16 @@ class Client extends Model
5959
public $plainSecret;
6060

6161
/**
62-
* Bootstrap the model and its traits.
62+
* Create a new Eloquent model instance.
6363
*
64+
* @param array $attributes
6465
* @return void
6566
*/
66-
public static function boot()
67+
public function __construct(array $attributes = [])
6768
{
68-
parent::boot();
69+
parent::__construct($attributes);
6970

70-
static::creating(function ($model) {
71-
if (Passport::clientUuids()) {
72-
$model->{$model->getKeyName()} = $model->{$model->getKeyName()} ?: (string) Str::orderedUuid();
73-
}
74-
});
71+
$this->usesUniqueIds = Passport::clientUuids();
7572
}
7673

7774
/**
@@ -205,6 +202,26 @@ public function confidential()
205202
return ! empty($this->secret);
206203
}
207204

205+
/**
206+
* Get the columns that should receive a unique identifier.
207+
*
208+
* @return array
209+
*/
210+
public function uniqueIds()
211+
{
212+
return Passport::clientUuids() ? [$this->getKeyName()] : [];
213+
}
214+
215+
/**
216+
* Generate a new key for the model.
217+
*
218+
* @return string
219+
*/
220+
public function newUniqueId()
221+
{
222+
return Passport::clientUuids() ? (string) Str::orderedUuid() : null;
223+
}
224+
208225
/**
209226
* Get the auto-incrementing key type.
210227
*

0 commit comments

Comments
 (0)