diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php b/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php index dc5192580f71..16ceef37ce3e 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php @@ -38,7 +38,7 @@ protected function compilePushOnce($expression) { $parts = explode(',', $this->stripParentheses($expression), 2); - [$stack, $id] = [$parts[0], $parts[1] ?? null]; + [$stack, $id] = [$parts[0], $parts[1] ?? '']; $id = trim($id) ?: "'".(string) Str::uuid()."'"; @@ -87,7 +87,7 @@ protected function compilePrependOnce($expression) { $parts = explode(',', $this->stripParentheses($expression), 2); - [$stack, $id] = [$parts[0], $parts[1] ?? null]; + [$stack, $id] = [$parts[0], $parts[1] ?? '']; $id = trim($id) ?: "'".(string) Str::uuid()."'"; diff --git a/tests/View/Blade/BladePrependTest.php b/tests/View/Blade/BladePrependTest.php index bccb64723c96..11bc1fa100da 100644 --- a/tests/View/Blade/BladePrependTest.php +++ b/tests/View/Blade/BladePrependTest.php @@ -2,6 +2,8 @@ namespace Illuminate\Tests\View\Blade; +use Illuminate\Support\Str; + class BladePrependTest extends AbstractBladeTestCase { public function testPrependIsCompiled() @@ -25,6 +27,22 @@ public function testPrependOnceIsCompiled() $expected = 'hasRenderedOnce(\'bar\')): $__env->markAsRenderedOnce(\'bar\'); $__env->startPrepend(\'foo\'); ?> test +stopPrepend(); endif; ?>'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + + public function testPrependOnceIsCompiledWhenIdIsMissing() + { + Str::createUuidsUsing(fn () => 'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f'); + + $string = '@prependOnce(\'foo\') +test +@endPrependOnce'; + + $expected = 'hasRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\')): $__env->markAsRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\'); +$__env->startPrepend(\'foo\'); ?> +test stopPrepend(); endif; ?>'; $this->assertEquals($expected, $this->compiler->compileString($string)); diff --git a/tests/View/Blade/BladePushTest.php b/tests/View/Blade/BladePushTest.php index 0f1addbfba9c..27d0041363ba 100644 --- a/tests/View/Blade/BladePushTest.php +++ b/tests/View/Blade/BladePushTest.php @@ -2,6 +2,8 @@ namespace Illuminate\Tests\View\Blade; +use Illuminate\Support\Str; + class BladePushTest extends AbstractBladeTestCase { public function testPushIsCompiled() @@ -24,6 +26,22 @@ public function testPushOnceIsCompiled() $expected = 'hasRenderedOnce(\'bar\')): $__env->markAsRenderedOnce(\'bar\'); $__env->startPush(\'foo\'); ?> test +stopPush(); endif; ?>'; + + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + + public function testPushOnceIsCompiledWhenIdIsMissing() + { + Str::createUuidsUsing(fn () => 'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f'); + + $string = '@pushOnce(\'foo\') +test +@endPushOnce'; + + $expected = 'hasRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\')): $__env->markAsRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\'); +$__env->startPush(\'foo\'); ?> +test stopPush(); endif; ?>'; $this->assertEquals($expected, $this->compiler->compileString($string));