Skip to content

Commit f8997fc

Browse files
authored
[12.x] Adds Laravel 11 support (#1702)
* Adds Laravel 11 support * Uses `publishesMigrations` * Adjusts install command
1 parent 1ab39f2 commit f8997fc

8 files changed

+57
-64
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ jobs:
1717
fail-fast: true
1818
matrix:
1919
php: ['8.0', 8.1, 8.2, 8.3]
20-
laravel: [9, 10]
20+
laravel: [9, 10, 11]
2121
exclude:
2222
- php: '8.0'
2323
laravel: 10
24+
- php: '8.0'
25+
laravel: 11
26+
- php: 8.1
27+
laravel: 11
2428
- php: 8.3
2529
laravel: 9
2630

@@ -45,4 +49,4 @@ jobs:
4549
composer update --prefer-dist --no-interaction --no-progress
4650
4751
- name: Execute tests
48-
run: vendor/bin/phpunit --verbose
52+
run: vendor/bin/phpunit

UPGRADE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## General Notes
44

5+
## Upgrading To 12.0 From 11.x
6+
7+
### Migration Changes
8+
9+
Passport 12.0 no longer automatically loads migrations from its own migrations directory. Instead, you should run the following command to publish Passport's migrations to your application:
10+
11+
```bash
12+
php artisan vendor:publish --tag=passport-migrations
13+
```
14+
515
## Upgrading To 11.0 From 10.x
616

717
### Minimum PHP Version

composer.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@
1717
"php": "^8.0",
1818
"ext-json": "*",
1919
"firebase/php-jwt": "^6.4",
20-
"illuminate/auth": "^9.0|^10.0",
21-
"illuminate/console": "^9.0|^10.0",
22-
"illuminate/container": "^9.0|^10.0",
23-
"illuminate/contracts": "^9.0|^10.0",
24-
"illuminate/cookie": "^9.0|^10.0",
25-
"illuminate/database": "^9.0|^10.0",
26-
"illuminate/encryption": "^9.0|^10.0",
27-
"illuminate/http": "^9.0|^10.0",
28-
"illuminate/support": "^9.0|^10.0",
20+
"illuminate/auth": "^9.0|^10.0|^11.0",
21+
"illuminate/console": "^9.0|^10.0|^11.0",
22+
"illuminate/container": "^9.0|^10.0|^11.0",
23+
"illuminate/contracts": "^9.0|^10.0|^11.0",
24+
"illuminate/cookie": "^9.0|^10.0|^11.0",
25+
"illuminate/database": "^9.0|^10.0|^11.0",
26+
"illuminate/encryption": "^9.0|^10.0|^11.0",
27+
"illuminate/http": "^9.0|^10.0|^11.0",
28+
"illuminate/support": "^9.0|^10.0|^11.0",
2929
"lcobucci/jwt": "^4.3|^5.0",
3030
"league/oauth2-server": "^8.5.3",
3131
"nyholm/psr7": "^1.5",
3232
"phpseclib/phpseclib": "^2.0|^3.0",
33-
"symfony/psr-http-message-bridge": "^2.1"
33+
"symfony/psr-http-message-bridge": "^2.1|^6.0|^7.0"
3434
},
3535
"require-dev": {
3636
"mockery/mockery": "^1.0",
37-
"orchestra/testbench": "^7.31|^8.11",
37+
"orchestra/testbench": "^7.35|^8.14|^9.0",
3838
"phpstan/phpstan": "^1.10",
39-
"phpunit/phpunit": "^9.3"
39+
"phpunit/phpunit": "^9.3|^10.4"
4040
},
4141
"autoload": {
4242
"psr-4": {

src/Console/InstallCommand.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ public function handle()
3535

3636
$this->call('passport:keys', ['--force' => $this->option('force'), '--length' => $this->option('length')]);
3737

38+
$this->call('vendor:publish', ['--tag' => 'passport-migrations']);
39+
3840
if ($this->option('uuids')) {
3941
$this->configureUuids();
4042
}
4143

44+
$this->call('migrate');
45+
4246
$this->call('passport:client', ['--personal' => true, '--name' => config('app.name').' Personal Access Client']);
4347
$this->call('passport:client', ['--password' => true, '--name' => config('app.name').' Password Grant Client', '--provider' => $provider]);
4448
}
@@ -51,22 +55,15 @@ public function handle()
5155
protected function configureUuids()
5256
{
5357
$this->call('vendor:publish', ['--tag' => 'passport-config']);
54-
$this->call('vendor:publish', ['--tag' => 'passport-migrations']);
5558

5659
config(['passport.client_uuids' => true]);
5760
Passport::setClientUuids(true);
5861

5962
$this->replaceInFile(config_path('passport.php'), '\'client_uuids\' => false', '\'client_uuids\' => true');
60-
$this->replaceInFile(database_path('migrations/2016_06_01_000001_create_oauth_auth_codes_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
61-
$this->replaceInFile(database_path('migrations/2016_06_01_000002_create_oauth_access_tokens_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
62-
$this->replaceInFile(database_path('migrations/2016_06_01_000004_create_oauth_clients_table.php'), '$table->bigIncrements(\'id\');', '$table->uuid(\'id\')->primary();');
63-
$this->replaceInFile(database_path('migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
64-
65-
if ($this->confirm('In order to finish configuring client UUIDs, we need to rebuild the Passport database tables. Would you like to rollback and re-run your last migration?')) {
66-
$this->call('migrate:rollback');
67-
$this->call('migrate');
68-
$this->line('');
69-
}
63+
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_auth_codes_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
64+
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_access_tokens_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
65+
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_clients_table.php'), '$table->bigIncrements(\'id\');', '$table->uuid(\'id\')->primary();');
66+
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_personal_access_clients_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
7067
}
7168

7269
/**
@@ -79,9 +76,11 @@ protected function configureUuids()
7976
*/
8077
protected function replaceInFile($path, $search, $replace)
8178
{
82-
file_put_contents(
83-
$path,
84-
str_replace($search, $replace, file_get_contents($path))
85-
);
79+
foreach (glob($path) as $file) {
80+
file_put_contents(
81+
$file,
82+
str_replace($search, $replace, file_get_contents($file))
83+
);
84+
}
8685
}
8786
}

src/Passport.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ class Passport
128128
*/
129129
public static $refreshTokenModel = 'Laravel\Passport\RefreshToken';
130130

131-
/**
132-
* Indicates if Passport migrations will be run.
133-
*
134-
* @var bool
135-
*/
136-
public static $runsMigrations = true;
137-
138131
/**
139132
* Indicates if Passport should unserializes cookies.
140133
*
@@ -689,18 +682,6 @@ public static function ignoreRoutes()
689682
return new static;
690683
}
691684

692-
/**
693-
* Configure Passport to not register its migrations.
694-
*
695-
* @return static
696-
*/
697-
public static function ignoreMigrations()
698-
{
699-
static::$runsMigrations = false;
700-
701-
return new static;
702-
}
703-
704685
/**
705686
* Instruct Passport to enable cookie serialization.
706687
*

src/PassportServiceProvider.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function boot()
3939
{
4040
$this->registerRoutes();
4141
$this->registerResources();
42-
$this->registerMigrations();
4342
$this->registerPublishing();
4443
$this->registerCommands();
4544

@@ -74,18 +73,6 @@ protected function registerResources()
7473
$this->loadViewsFrom(__DIR__.'/../resources/views', 'passport');
7574
}
7675

77-
/**
78-
* Register the Passport migration files.
79-
*
80-
* @return void
81-
*/
82-
protected function registerMigrations()
83-
{
84-
if ($this->app->runningInConsole() && Passport::$runsMigrations && ! config('passport.client_uuids')) {
85-
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
86-
}
87-
}
88-
8976
/**
9077
* Register the package's publishable resources.
9178
*
@@ -94,7 +81,11 @@ protected function registerMigrations()
9481
protected function registerPublishing()
9582
{
9683
if ($this->app->runningInConsole()) {
97-
$this->publishes([
84+
$publishesMigrationsMethod = method_exists($this, 'publishesMigrations')
85+
? 'publishesMigrations'
86+
: 'publishes';
87+
88+
$this->{$publishesMigrationsMethod}([
9889
__DIR__.'/../database/migrations' => database_path('migrations'),
9990
], 'passport-migrations');
10091

src/PassportUserProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public function validateCredentials(Authenticatable $user, array $credentials)
7474
return $this->provider->validateCredentials($user, $credentials);
7575
}
7676

77+
/**
78+
* {@inheritdoc}
79+
*/
80+
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false)
81+
{
82+
$this->provider->rehashPasswordIfRequired($user, $credentials, $force);
83+
}
84+
7785
/**
7886
* Get the name of the user provider.
7987
*

testbench.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
providers:
22
- Laravel\Passport\PassportServiceProvider
33

4-
migrations: true
5-
4+
migrations:
5+
- database/migrations

0 commit comments

Comments
 (0)