laravel / folio

Page based routing for Laravel.
MIT License
568 stars 46 forks source link

[1.x] Fixes `route()` base uri, domain, and query parameters #88

Closed nunomaduro closed 1 year ago

nunomaduro commented 1 year ago

Fixes https://github.com/laravel/folio/issues/85.

This pull request fixes three things when using the route() function and adds versioning to the cache generated by Folio's routes:

  1. Extra parameters sent as the second parameter to the route() function are now sent as query parameters, just like the regular behavior of the route() function.
// before:
route('posts', ['page' => 1], false); // /posts
// with this pr:
route('posts', ['page' => 1], false); // /posts?page=1
  1. The base URI of the mounted path is now respected. For example, Folio::uri('/1')->path(...) will generate a URL that contains that URI.
Folio::uri('/v1')->path('pages/version-one');

// before:
route('posts', ['page' => 1], false); // /posts
// with this pr:
route('posts', ['page' => 1], false); // /v1/posts?page=1
  1. The domain of the Folio's mount is now respected, similar to the regular behavior of the route() function. For example, Folio::domain('podcasts.com')->... will generate a route() result with the http://podcasts.com/{...} domain.
Folio::domain('{account}.podcasts.com')->uri('/v1')->path('pages/version-one');

// before:
route('posts', ['account' => 'foo', 'page' => 1]); // http://localhost/posts
// with this pr:
route('posts', ['account' => 'foo', 'page' => 1]); // http://foo.podcasts.com/posts
  1. Finally, versioning is introduced to the cache. This means that if FolioRoutes::version changes, the cached version is ignored until a new route:cache command is invoked.