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

Fix unnamed routes when views are disabled (with original code formatting) #571

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

cima-alfa
Copy link
Contributor

This PR fixes additional unnamed routes, such as login and register, when views are disabled.
It also fixes the issue with breadcrumbs potentially not working when GET routes don't have a name. (#368 (comment))

In the current state, routes like login and register have to be hardcoded since they don't have names when views are disabled.

@taylorotwell
Copy link
Member

I'm finding this PR a bit confusing. Why are we only naming routes when views are disabled? 😅

@cima-alfa
Copy link
Contributor Author

cima-alfa commented Oct 17, 2024

I am using Ziggy JS to use Laravel’s named routes in my NextJS frontend. This allows me not having to hardcode the routes in the Frontend part. Login, register and some other routes don’t have names (others do) so I am forced to hardcode only those few routes.

Edit: For example right now in the Frontend part I have to hardcode the entire fetch url like this await fetch(“https://domain.tld/login”, ...) instead of simply using await fetch(route(“login”), ...) which would return the same thing.

Edit 2: We are not naming routes only when not using views. Names while using views are still working. We are just adding names to the post routes in case views are disabled.

Right now in the code you can see that the login, register and other affected routes are getting names on their GET definitions. When views are disabled, these never ger defined. Therefore the post routes remain unnamed.
If you are wondering why not just add the names to the post routes instead of their get counterparts, you can refer to the comment linked in the original post.

@taylorotwell taylorotwell merged commit 0e9c9ec into laravel:1.x Oct 18, 2024
9 checks passed
@enrymari
Copy link

Before this update i used to modifify fortify routes.php to register login route with get method, even if views are disabled, to allow the login page (in vue).
This patch don't resolve the problem becouse assign the post method with the name 'login'.
There're some different workaround?

@cima-alfa
Copy link
Contributor Author

I don't think your case is an issue with my proposal. However I have the same use case as you in my current project.
I solved it by simply naming the get route front.login. So I have a POST login route that is part of fortify and a GET front.login route that I use in my Next.js frontend. I also prefixed all fortify routes with /api because I consider those part of my api backend.

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 this pull request may close these issues.

3 participants