Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Illuminate/Foundation/ComposerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\Installer\PackageEvent;
use Composer\Script\Event;
use Illuminate\Container\Container;
use Illuminate\Contracts\Console\Kernel;

class ComposerScripts
Expand Down Expand Up @@ -67,9 +68,10 @@ public static function prePackageUninstall(PackageEvent $event)
define('LARAVEL_START', microtime(true));
}

/** @var Application $app */
$app = require_once $bootstrapFile;
require_once $bootstrapFile;
Copy link
Contributor

@AhmedAlaa4611 AhmedAlaa4611 Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still need require_once $bootstrapFile; and we have Container::getInstance()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require_once $bootstrapFile fetches the user-defined Application builder. This will resolve the Container's instance during its setup.

The first time you call require_once $bootstrapFile, it does return an instance of Application. If you call it again during the life-cycle, it just returns true. (See the documentation for include_once where this behavior is mentioned).

The reason this is necessary is if you call composer remove laravel/telescope laravel/boost, this does not tear down and reboot the php interpreter for each package being removed. So for the first package removed, ComposerScripts::prePackageUninstall() is called, where require_once DOES return the application, but for the second package require_once just returns true.

Thus, this change:

  • ensures we have built the application according to project's application builder (bootstrap/app.php)
  • accesses the Application via the Container facade
  • ensures if we are removing multiple packages, it still works

Let me know if that makes sense or if you have any other questions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That makes sense now. Other small question; do you think we should document the work done in #57144 and laravel/telescope#1641 in the package documentation, so developers can use this feature in their own packages when they need to register a service provider in the bootstrap/providers.php file?


/** @var Application $app */
$app = Container::getInstance();
$app->make(Kernel::class)->bootstrap();

/** @var \Composer\DependencyResolver\Operation\UninstallOperation $uninstallOperation */
Expand Down