Skip to content

[13.x] Fix using elsePushIf blade directive with complex conditions - #61741

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
mrjavadseydi:13.x-fix-else-push-if-with-commas
Sep 26, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
mrjavadseydi:13.x-fix-else-push-if-with-commas

Conversation

@mrjavadseydi

Copy link
Copy Markdown
Contributor

this pr fixes @elsePushIf directive when condition have multiple commas.

this problem was already fixed for @pushIf in #57274 (related issue: #57264), since that fix is already merged and confirmed, but the original pr missed fixing @elsePushIf, so i implemented the same fix for it here.

Cause: compileElsePushIf() uses explode(',', ..., 2), which splits at the first comma.

Before

@pushIf(true, 'stack')
if
@elsePushIf(in_array($x, [3, 4]), 'scripts')
elseif
@endPushIf

To:

<?php if(true): $__env->startPush( 'stack'); ?>
if
<?php $__env->stopPush(); elseif(in_array($x): $__env->startPush( [3, 4]), 'scripts'); ?>
elseif
<?php $__env->stopPush(); endif; ?>

❌ compiled incorrectly: the condition get split at it's first comma, which is a PHP parse error.

After

✅ compiles correctly:

@pushIf(true, 'stack')
if
@elsePushIf(in_array($x, [3, 4]), 'scripts')
elseif
@endPushIf

To:

<?php if(true): $__env->startPush( 'stack'); ?>
if
<?php $__env->stopPush(); elseif(in_array($x, [3, 4])): $__env->startPush('scripts');
elseif
<?php $__env->stopPush(); endif; ?>

@taylorotwell
taylorotwell merged commit 5f6de89 into laravel:13.x Sep 26, 2026
62 checks passed
@mrjavadseydi
mrjavadseydi deleted the 13.x-fix-else-push-if-with-commas branch September 26, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants