From ed93be86d2909a3de4df23a7443ccbef56826d32 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 4 Mar 2024 13:57:10 +0000 Subject: [PATCH] Ensures migration gets published just once (#50361) --- .../Foundation/Console/ApiInstallCommand.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Foundation/Console/ApiInstallCommand.php b/src/Illuminate/Foundation/Console/ApiInstallCommand.php index 9bab2abda4c4..6c7c21fbe0e1 100644 --- a/src/Illuminate/Foundation/Console/ApiInstallCommand.php +++ b/src/Illuminate/Foundation/Console/ApiInstallCommand.php @@ -93,14 +93,18 @@ protected function installSanctum() 'laravel/sanctum:^4.0', ]); - $php = (new PhpExecutableFinder())->find(false) ?: 'php'; - - $result = Process::run([ - $php, - defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan', - 'vendor:publish', - '--provider', - 'Laravel\\Sanctum\\SanctumServiceProvider', - ]); + $migrationPublished = collect(scandir($this->laravel->databasePath('migrations')))->contains(function ($migration) { + return preg_match('/\d{4}_\d{2}_\d{2}_\d{6}_create_personal_access_tokens_table.php/', $migration); + }); + + if (! $migrationPublished) { + Process::run([ + (new PhpExecutableFinder())->find(false) ?: 'php', + defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan', + 'vendor:publish', + '--provider', + 'Laravel\\Sanctum\\SanctumServiceProvider', + ]); + } } }