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

Routes won't be registered automatically #4

Open
captainscorch opened this issue Dec 1, 2020 · 5 comments
Open

Routes won't be registered automatically #4

captainscorch opened this issue Dec 1, 2020 · 5 comments

Comments

@captainscorch
Copy link

After successfully installing everything via composer require and setting up the Middleware and updating the .ENV variables with the Quick setup via php artisan. Everything worked fine. After clearing config, view and route cache I reloaded the website but nothing happened. I got a 404 error that the page was not found (/stagefront or /login). I checked the web.php routes file and it didn't have any new configuration or code added. I had to manually add the code from the repo under routes/routes.php to my web.php in order for Stagefront to work properly.

I don't think this is a proper solution nor the indented behaviour as your Readme states Routes should be registered automatically. I'm using Laravel 8.16.1 and "codezero/laravel-stagefront": "^2.3"

If you need any code or other info please let me know.

@ivanvermeyen
Copy link
Contributor

Hmm not as intended indeed.
Can you double check if the STAGEFRONT_ENABLED setting is true?

Routes are loaded if it is true only:

if (Config::get('stagefront.enabled') === true) {

@captainscorch
Copy link
Author

STAGEFRONT_ENABLED=true was enabled in the .env file.

After removing the routes code from the web.php file again I ran some artisan commands (clear config, clear view, clear cache, etc.). After running php artisan route:cache I reloaded the website and got redirected to the Stagefront login page. It seems like (now with Laravel 8 maybe?) you have to clear the route cache and renew it in order for the Stagefront routes to work.

Hope that helps you to maybe find a solution for that behaviour or maybe adding this to the documentation in case you can reproduce the same problem.

@ivanvermeyen
Copy link
Contributor

ivanvermeyen commented Dec 1, 2020

If I understand correctly, your routes were already cached when you enabled StageFront?
In that case it makes sense, because Laravel won't reload the route files, but use the cached ones (as far as I know).
When I deploy I always recache routes/config/etc. hence I never encountered this issue.

If you want to enable/disable on runtime (while routes are cached), that means we can't rely on route caching for the StageFront routes. We would need to load the routes another way.

Edit: same goes for the config cache. Which we probably can't bypass...

@captainscorch
Copy link
Author

That's correct. I worked locally with Valet and by default, Routes are cached I think. When deploying with Forge for example, Routes should be recached automatically so it shouldn't be an issue then.

As you said, there is probably no solution for taking care of updating the cache automatically after setting up StageFront without a major change in how routes are working currently.

I guess the easiest solution would be to just add a note or section to the Documentation with the php artisan route:cache Artisan Command to make sure Routes are recached after the setup.

Feel free to close the Issue, everything is working perfectly fine now!

@ivanvermeyen
Copy link
Contributor

Hmm, routes shouldn't be cached by default, unless you or your deploy script caches them.
But yes, if routes have been cached, you need to recache them when enabling/disabling StageFront.

I will leave this open until I add a note of this to the readme.
Thanks for pointing this out. 👍

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

2 participants