From 9619f5603433b4a0bd9681e8ba70b3d446e41b83 Mon Sep 17 00:00:00 2001
From: Jason McCreary <jason@pureconcepts.net>
Date: Wed, 19 Jun 2024 12:00:30 -0400
Subject: [PATCH] Chop PHP extension when passed to `make` commands (#51842)

---
 src/Illuminate/Console/GeneratorCommand.php       |  8 +++++++-
 .../Integration/Console/GeneratorCommandTest.php  | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/Illuminate/Console/GeneratorCommand.php b/src/Illuminate/Console/GeneratorCommand.php
index 67b34ce8697b..07913bd67eac 100644
--- a/src/Illuminate/Console/GeneratorCommand.php
+++ b/src/Illuminate/Console/GeneratorCommand.php
@@ -417,7 +417,13 @@ protected function sortImports($stub)
      */
     protected function getNameInput()
     {
-        return trim($this->argument('name'));
+        $name = trim($this->argument('name'));
+
+        if (Str::endsWith($name, '.php')) {
+            return Str::substr($name, 0, -4);
+        }
+
+        return $name;
     }
 
     /**
diff --git a/tests/Integration/Console/GeneratorCommandTest.php b/tests/Integration/Console/GeneratorCommandTest.php
index cb8ce75a6818..0709691166c1 100644
--- a/tests/Integration/Console/GeneratorCommandTest.php
+++ b/tests/Integration/Console/GeneratorCommandTest.php
@@ -2,11 +2,26 @@
 
 namespace Illuminate\Tests\Integration\Console;
 
+use Orchestra\Testbench\Concerns\InteractsWithPublishedFiles;
 use Orchestra\Testbench\TestCase;
 use PHPUnit\Framework\Attributes\DataProvider;
 
 class GeneratorCommandTest extends TestCase
 {
+    use InteractsWithPublishedFiles;
+
+    protected $files = [
+        'app/Console/Commands/FooCommand.php',
+    ];
+
+    public function testItChopsPhpExtension()
+    {
+        $this->artisan('make:command', ['name' => 'FooCommand.php'])
+            ->assertExitCode(0);
+
+        $this->assertFilenameExists('app/Console/Commands/FooCommand.php');
+    }
+
     #[DataProvider('reservedNamesDataProvider')]
     public function testItCannotGenerateClassUsingReservedName($given)
     {