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

PHP expression runs twice when passing to blade component #50777

Closed
mokhosh opened this issue Mar 26, 2024 · 2 comments
Closed

PHP expression runs twice when passing to blade component #50777

mokhosh opened this issue Mar 26, 2024 · 2 comments

Comments

@mokhosh
Copy link
Contributor

mokhosh commented Mar 26, 2024

Laravel Version

11.0.8

PHP Version

8.3.3

Database Driver & Version

No response

Description

If you use a method to pass data to a blade component, the method will be run twice, leading to unexpected behaviour.

For example, you would think this will simply shift the first item, and pass it to the component:

<x-article :article="$articles->shift()"/>

But it removes two items from the $articles collection.

You would have to do something like this to fix it:

@php($first = $articles->shift())
<x-article-card :article="$first"/>

Steps To Reproduce

  1. Create a blade component with a prop
  2. Use that component in another blade template
  3. Create a collection of 4 items and pass the first item to the component using shift
  4. Dump the collection after the component
@danharrin
Copy link
Contributor

Ref #50403 #50479

@driesvints
Copy link
Member

Using the solution from above is, for now at least, the only one.

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

3 participants