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

Casts method inside HasFlexible trait #389

Open
vladles opened this issue Sep 19, 2022 · 7 comments · May be fixed by #409
Open

Casts method inside HasFlexible trait #389

vladles opened this issue Sep 19, 2022 · 7 comments · May be fixed by #409

Comments

@vladles
Copy link

vladles commented Sep 19, 2022

Inside the HasFlexible trait (which we're using in FlexibleCast) we're returning the raw value (string) when in the following context :

if(app()->getProvider(NovaServiceProvider::class) && !app()->runningInConsole() && !app()->environment('testing')) {
    return $value;
}

In other words, if you're testing inside Nova itself it won't return the casted value (because the field will take care of it by itself). Is that your case ?

Originally posted by @toonvandenbos in #311 (comment)

Could you explain this case - for what we need returns $value string if we want to use CASTS features?

@vladles
Copy link
Author

vladles commented Sep 19, 2022

Maybe you meant the opposite?

if(!app()->getProvider(NovaServiceProvider::class) && app()->runningInConsole() && app()->environment('testing')) {

@vladles
Copy link
Author

vladles commented Sep 19, 2022

When I apply this code in MyFlexibleCast class and implements it for custom class, I faced with issue with laravel-nova pages, we faced the problem "Undefined property: stdClass::$layout".
After a few minutes research I noticed that this happened in Whitecube\NovaFlexibleContent\Value\Resolver class extractValueFromResource method.
This happened because we do data_get method from our resource and it's returns to us casts data, but we should recievied non-casts data from table.

// $value = data_get($resource, str_replace('->', '.', $attribute)) ?? [];
$value = $resource->getRawOriginal(str_replace('->', '.', $attribute)) ?? [];

And we can just call the getRawOriginal method (laravel 7+). And everything will be works!

@HeadStudios
Copy link

Man... trying all this stuff now - I'm so confused so just changed this in whitecube and hoepfully it'll stop returning a string..

@HeadStudios
Copy link

Lol nope - https://share.getcloudapp.com/d5unwGr9 - I know this is... something as I'm close and it works in routes.. just not in... like anywhere else - just returning a string.

@HeadStudios
Copy link

Ahhh! That's all I want - https://share.getcloudapp.com/wbuQ9RyW - I'm going crazy here lol - got phpStorm open trying to do this

@vladles
Copy link
Author

vladles commented Sep 27, 2022

Ahhh! That's all I want - https://share.getcloudapp.com/wbuQ9RyW - I'm going crazy here lol - got phpStorm open trying to do this

Sorry for the delay, did you solve your problem?

@HeadStudios
Copy link

Hey!! Nah it's all good and great timing - I actually just figured out today how to like... create a templating system using your flexible field thingie (populate rows on drop down of my other Vue element)... so yeh - it works awesomely! Please don't leave again! Haha... I guess I need to like show my support and sponsor you guys otherwise I can't really complain if you guys go AWOL for months lol

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 a pull request may close this issue.

2 participants