outl1ne / nova-page-manager

Static page and region manager for Laravel Nova - designed for headless CMS's.
MIT License
180 stars 39 forks source link

config:cache #51

Closed veneliniliev closed 3 years ago

veneliniliev commented 4 years ago

we have problem with config:cache / optimize and closures in config...

In ConfigCacheCommand.php line 71:
Your configuration files are not serializable.  

here has some info for this problem: https://github.com/laravel/framework/issues/9625

example from config:

 'locales' => function () {
        return ['ex', 'am', 'ple'];
 },
'page_url' => function (Page $page) {
       return env('FRONTEND_URL') . '/' . $page->path;
},
liorocks commented 3 years ago

@veneliniliev

I had a similar problem a while ago and this is how I solved it.

// config/nova-page-manager.php

'page_url' => \App\Helpers\NovaPageManagerHelper::class . '::pageUrl',
// app/Helpers/NovaPageManagerHelper.php

<?php

namespace App\Helpers;

use OptimistDigital\NovaPageManager\Models\Page;

class NovaPageManagerHelper
{
    public static function pageUrl(Page $page)
    {
        return route('page.show', $page->locale . $page->path);
    }
}

Hope this helps!