-
Notifications
You must be signed in to change notification settings - Fork 47
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
[1.x] Adds name
function
#79
Conversation
Fantastic work! The use of a However, there's one thing we might need to reconsider - the continued use of the To get the name, we have to navigate through the directory to run the From what I understand, the original code was designed to avoid having to go through the directory for each request, and to bypass the need to cache the routes in the same way, leading to the creation of the But now, we're navigating through the directory again! This raises a question - should we really continue using the |
I'm repeating this here since you said let's continue the discussion here. Can we generate route names based on a convention if no route name is explicitly declared? |
@mokhosh anything that generates route names by conventions is inherently tied to the file structure in some way - which defeats the purpose of named routes entirely since the route names would change when you move / rename files. |
@snellingio I agree that in a perfect world Folio would likely register an individual, matching route for each page in each mounted directory. However, careful consideration would have to be given to the order they are registered and the process would be a bit slow in local development. You are correct that if you are using Folio you can no longer use |
Good point, but i don't think it's a problem we can't solve. We can have a folio:mv artisan command that puts the explicit named route before moving if it's not there. |
This pull request fixes #48, and it introduces a new
name
function to Laravel Folio - that allows to basically define a route name for a specific page, and access any Folio's route using the regularroute
helper. Here is an example:And, of course, everything you would expect regarding arguments just works with this function, assuming that these files contain
name('users.show')
in their content. Here is how the route helper can be used:In addition, in production, when developers use
route:cache
, Folio will automatically cache all the routes names defined using thename
function, avoiding any performance issues. The "cached" file is stored atbootstrap/cache/folio-routes.php
.Finally, if a route is missing parameters or if a parameter contains the
null
value, aLaravel\Folio\Exceptions\UrlGenerationException
is thrown, similar toIlluminate\Routing\Exceptions\UrlGenerationException
.