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

[7.1.2] Laravel 7 component syntax broken with models #715

Closed
faustbrian opened this issue Mar 14, 2020 · 9 comments
Closed

[7.1.2] Laravel 7 component syntax broken with models #715

faustbrian opened this issue Mar 14, 2020 · 9 comments
Labels

Comments

@faustbrian
Copy link
Contributor

@faustbrian faustbrian commented Mar 14, 2020

After updating to Laravel 7.1.2 which shipped laravel/framework@ae4d790 it doesn't seem to be possible anymore to pass models to blade components because they are turned into JSON which results in a string being passed to the mount method of a component.

Using the old @livewire directive works just fine so it's just a matter of inconsistency in the behaviour of how directives and the component syntax are handled on Laravel's end.

This isn't directly a Livewire issue but the documentation contains examples that make usage of models which obviously is a common use-case. Should this simply be documented or should Livewire provide a workaround to work with models and the new component syntax? @calebporzio

@telkins

This comment has been minimized.

Copy link

@telkins telkins commented Mar 14, 2020

I came here yesterday suspecting the same thing, but didn't see anything about it.

I was questioning whether or not I was using livewire correctly. After a bit of back and forth and more than a little wasted time, I realized that I had updated my composer dependencies. I thought maybe something in livewire changed, but that wasn't the case.

Anyway, today I ran my code, which failed for the same reasons @faustbrian mentioned. Reverting my composer packages (laravel/framework 7.1.2 -> 7.1.0) allowed the code to work again.

Not sure that this is a livewire issue or not, but it needs to be addressed one way or another...especially if laravel/framework 7.1.2 closes some security holes.

@telkins

This comment has been minimized.

Copy link

@telkins telkins commented Mar 14, 2020

Ah...I didn't notice that one could use "the old @livewire directive". I'll upgrade and give that a try. Thx, @faustbrian .

@calebporzio

This comment has been minimized.

Copy link
Collaborator

@calebporzio calebporzio commented Mar 14, 2020

@faustbrian - ooh that's rough. Can you fill me in on the issue that caused the Laravel change? Like exactly what was the security threat that caused that change, and does that apply to us as well.

@telkins

This comment has been minimized.

Copy link

@telkins telkins commented Mar 14, 2020

@calebporzio Not sure this helps much, but this is what I saw the other day: https://blog.laravel.com/security-laravel-712-released

@telkins

This comment has been minimized.

Copy link

@telkins telkins commented Mar 14, 2020

Still not sure, but this might be the commit that Taylor was referring to: laravel/framework@ae4d790

@faustbrian

This comment has been minimized.

Copy link
Contributor Author

@faustbrian faustbrian commented Mar 15, 2020

What @telkins linked is the official information from Taylor and the PR/commit. I think the issue affects us much as it does Laravel, which would be when developers pass around user input without any checks into blade components.

I am not entirely sure though why @component/@livewire work fine but using the new component syntax as x-component/livewire:component are broken. I haven't yet digged into the code but would've assumed that they use the same underlying logic to sanitize and transform data, which doesn't seem to be the case because models still work with @component/@livewire.

So I am not sure if we should just add some information to the Livewire documentation that you should use @livewire if you intend to use models for your mount method parameters.

// works
@component('something', ['model' => $model])

// works
@livewire('something', ['model' => $model])

// does not work anymore
<x-something :model="$model" />

// does not work anymore
<livewire:something :model="$model" />
@mikebronner

This comment has been minimized.

Copy link

@mikebronner mikebronner commented Mar 17, 2020

I think this might be related, so I hope it's OK to post here.

I found that I had to revert back to LiveWire 1.0.4 (using Laravel 7.1.3) to get wire:model= to work in my components. I have the following input field in a component:

                    <input
                        class="ml-3 my-1 w-48"
                        wire:model="search"
                        type="text"
                        placeholder="Search..."
                    >

This would only pass NULL when using LiveWire above version 1.0.4.

Please feel free to move to it's own issue, if not related.

@intellow

This comment has been minimized.

Copy link
Contributor

@intellow intellow commented Mar 18, 2020

Just came here to chime in and say I'm seeing the same issue where I can't pass a model into mount. (edited: I thought it was working on an earlier version of Livewire, but I was wrong)

@calebporzio

This comment has been minimized.

Copy link
Collaborator

@calebporzio calebporzio commented Mar 18, 2020

K, fixed in v1.0.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.