rcrowe / TwigBridge

Give the power of Twig to Laravel
MIT License
895 stars 165 forks source link

Does not understand 'Higher Order Messages' #359

Open Dylan-DutchAndBold opened 5 years ago

Dylan-DutchAndBold commented 5 years ago

I have this line of code in Twig: user.roles.first.is(role) to truth check if I should set an option to selected. This should translate to $user->roles->first->is($role). But it seems to do something more in the ballpark of this $user->roles->first()->is($role)

This is what getAttribute resolves into: screenshot 2018-12-24 at 11 49 50

This is what it should resolve into: screenshot 2018-12-24 at 11 49 27

Dylan-DutchAndBold commented 5 years ago

I believe it goes bad on line 582 of Twig\Template. It does an isset check of the property. But since the HigherOrderCollectionProxy is created in the magic __get method of a Collection. It returns false and tries it as a function.

Dylan-DutchAndBold commented 5 years ago

I have created a possible solution to this issue, it actually does the same as what it does for a Model class objects. However this does mean that if you'd use to use something like this before: user.roles.first.name, it will now no longer work. You'd now have to write user.roles.first().name. So this might be unwanted.