Stillat / the-agency-starter-kit

The Agency is a free Statamic Starter Kit designed as an example of utilizing various techniques to implement a highly customized Statamic experience.
MIT License
5 stars 2 forks source link

Extend navigation issue with upgrade to Laravel 11 & CMS v5 #5

Open jeremyvienney opened 1 month ago

jeremyvienney commented 1 month ago

Hello !

I use part of your starter kit as boilerplate to extend the cp, after migrated last night to Statamic 5 & Laravel 11, I have this issue from boot method from AppServiceProvider. Route [statamic.cp.project-board] not defined. (View: /Users/jeremy/Dev/Web/valet/stories-studio-v5/vendor/statamic/cms/resources/views/layout.blade.php)

The issue is coming from the line 33 of AppServiceProvider $this->addProjectNav();

Here is a flare sharing report in case you need more infos : https://flareapp.io/share/omwXkVXP#main

It may be related to a new order in middleware call from laravel 11 but i'm not sure what to do.

What do you think about it ?

Thanks !

Jérémy.

JohnathonKoster commented 1 month ago

Hi there - I have not tried to port that project to the latest Statamic or Laravel versions yet, so don't have anything super helpful to add other than it seems the routes/cp.php file might not being included 🤔

Are you able to run the following?

php artisan route:clear
php artisan route:list
jeremyvienney commented 1 month ago

Thanks you John, you guided me to the real issue. In Laravel 11 there is no more RouteServiceProvider file. I tried to add in bootstrap/app.php this code from the doc (https://laravel.com/docs/11.x/routing#routing-customization) :

->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
        then: function () {
            Route::prefix('cp')
                ->middleware('statamic.cp.authenticated')
                ->group(base_path('routes/cp.php'));
            }
    )

But it didn't added to statamic group... So figuring deeper, I saw that the method pushToCpRoutes could be added to AppServiceProvider too... and voilà ! :) So the only change you maybe have to make to upgrade the starter kit to laravel 11 is to move this to AppServiceProvider :

 Statamic::pushCpRoutes(function () {
            // Include our routes/cp.php file to make
            // it easier to manage our Control Panel
            // routes in a separate file. By including
            // that file as this point, we can be
            // sure that they are loaded at the
            // correct time when Statamic loads.
            require_once base_path('routes/cp.php');
        });
JohnathonKoster commented 1 month ago

Thanks for posting your results/follow up!