Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined constant error when try to define dynamic slot names #42932

Closed
monurakkaya opened this issue Jun 24, 2022 · 1 comment
Closed

undefined constant error when try to define dynamic slot names #42932

monurakkaya opened this issue Jun 24, 2022 · 1 comment

Comments

@monurakkaya
Copy link
Contributor

monurakkaya commented Jun 24, 2022

  • Laravel Version: 9.18.0
  • PHP Version: 8.1.2
  • Database Driver & Version:

Description:

Since v9.15, After the merge of this pull request: #42574

<x-slot :name="$language->code"> 

throws error as undefined constant "code". Because compiled view is looking like this:

<?php $__env->slot($language>code null, []); ?> <?php echo e($language->name); ?> <?php $__env->endSlot(); ?>
instead
<?php $__env->slot($language->code null, []); ?> <?php echo e($language->name); ?> <?php $__env->endSlot(); ?>
Because it's trying to make camel case $language->code

Steps To Reproduce:

create a blade component:

php artisan make:component Test

In any blade file:

(It does not matter content of the x-test component below)

@php
    $languages = [
        [
            'name' => 'Turkish',
            'code' => 'tr'
        ],
        [
            'name' => 'English',
            'code' => 'en'
        ]
    ];

    $languagesAsArrayOfObjects = [
        (object)[
            'name' => 'Turkish',
            'code' => 'tr'
        ],
        (object)[
            'name' => 'English',
            'code' => 'en'
        ]
    ];
@endphp


##Works
<x-test>
    @foreach($languages as $language)
        <x-slot :name="$language['code']">{{ $language['name'] }}</x-slot>
    @endforeach
</x-test>

<br><br>

##Works
<x-test>
    <x-slot name="tr">Turkish</x-slot>
    <x-slot name="en">English</x-slot>
</x-test>


<br><br>

###Does not work (undefined constant code)
<x-test>
    @foreach($languagesAsArrayOfObjects as $language)
        <x-slot :name="$language->code">{{ $language->name }}</x-slot>
    @endforeach
</x-test>

<br><br>

##Works

<x-test>
    @foreach($languagesAsArrayOfObjects as $language)
        @php($code = $language->code)
        <x-slot :name="$code">{{ $language->name }}</x-slot>
    @endforeach
</x-test>

@driesvints
Copy link
Member

Closing this as a PR was opened. Thanks

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

No branches or pull requests

2 participants