Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/Illuminate/View/Compilers/Concerns/CompilesStacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()."'";

Expand Down Expand Up @@ -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()."'";

Expand Down
18 changes: 18 additions & 0 deletions tests/View/Blade/BladePrependTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Tests\View\Blade;

use Illuminate\Support\Str;

class BladePrependTest extends AbstractBladeTestCase
{
public function testPrependIsCompiled()
Expand All @@ -25,6 +27,22 @@ public function testPrependOnceIsCompiled()
$expected = '<?php if (! $__env->hasRenderedOnce(\'bar\')): $__env->markAsRenderedOnce(\'bar\');
$__env->startPrepend(\'foo\'); ?>
test
<?php $__env->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 = '<?php if (! $__env->hasRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\')): $__env->markAsRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\');
$__env->startPrepend(\'foo\'); ?>
test
<?php $__env->stopPrepend(); endif; ?>';

$this->assertEquals($expected, $this->compiler->compileString($string));
Expand Down
18 changes: 18 additions & 0 deletions tests/View/Blade/BladePushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Tests\View\Blade;

use Illuminate\Support\Str;

class BladePushTest extends AbstractBladeTestCase
{
public function testPushIsCompiled()
Expand All @@ -24,6 +26,22 @@ public function testPushOnceIsCompiled()
$expected = '<?php if (! $__env->hasRenderedOnce(\'bar\')): $__env->markAsRenderedOnce(\'bar\');
$__env->startPush(\'foo\'); ?>
test
<?php $__env->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 = '<?php if (! $__env->hasRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\')): $__env->markAsRenderedOnce(\'e60e8f77-9ac3-4f71-9f8e-a044ef481d7f\');
$__env->startPush(\'foo\'); ?>
test
<?php $__env->stopPush(); endif; ?>';

$this->assertEquals($expected, $this->compiler->compileString($string));
Expand Down