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

Cant use helper functions in Nova #72

Closed
matthewjumpsoffbuildings opened this issue Mar 16, 2021 · 6 comments
Closed

Cant use helper functions in Nova #72

matthewjumpsoffbuildings opened this issue Mar 16, 2021 · 6 comments

Comments

@matthewjumpsoffbuildings

Im trying to use the nova_get_regions() helper function within Nova itself, so I can pull in some region data and display it in a Field

For some reason this causes some kind of infinite loop, hang or crash? The page just times out. Is there a way I can access region or page data within Nova without this happening?

@KasparRosin
Copy link
Member

Hey @matthewjumpsoffbuildings

I was unable to reproduce the issue with my nova. Could you provide more information/reproducible code example so we can take another look at this issue.

@matthewjumpsoffbuildings
Copy link
Author

In one of my Templates, I had a static function regions() which simply called nova_get_regions() and returned that as an associative array. Then in my Field definitions I was trying to use some of the data from that (some colors set in a different region), to prefill the palette of a Color field.

@KasparRosin
Copy link
Member

$regions = nova_get_regions();
$titles = collect($regions)->pluck('data')->pluck('et.title')->filter();
 return [
     Select::make('Titles')->options($titles),
]

I tried to reproduce the issue with code above but was unable to.
Could be an issue with the colour field/invalid data.

Closing this at the moment since i can't find a reason how this could be regions/page-manager issue.

@matthewjumpsoffbuildings
Copy link
Author

It didn't matter if I actually implemented the retrieved values into the Color Field (or any other field). The mere presence of the nova_get_regions() in my Template was enough to crash the app.

I was actually caching the response of nova_get_regions() using Laravels Cache helper? Could that be the source of the issue?

Heres a rough example

class AppController extends Controller
{
	public static function regions()
	{
		return Cache::remember('regions', 60, function(){
			return nova_get_regions();
		});
	}

My Template

class Shortlist extends Template
{
	public static $type = 'region';
	public static $name = 'Shortlist';

	public function fields(Request $request): array
	{
		$regions = AppController::regions();
		return [ ...

Even if I do nothing with $regions, just having the call to nova_get_regions() in the static function in AppController is enough to break it

@KasparRosin KasparRosin reopened this Apr 19, 2021
@KasparRosin
Copy link
Member

KasparRosin commented Apr 19, 2021

My bad, this seems to be the problem indeed when calling nova_get_regions inside region template.
I was testing this inside a page template, which was the reason why i wasn't able to reproduce.

@matthewjumpsoffbuildings
Copy link
Author

No worries. Right now Im getting around it by just using the Region::all() method to get all the regions data, that doesn't crash anything, though the data is formatted a bit differently than it would be from nova_get_regions()

@Tarpsvo Tarpsvo closed this as completed Sep 2, 2021
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