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

[4.x] Add tenant parameter to defaults() in UrlGeneratorBootstrapper #1311

Merged
merged 13 commits into from
Feb 14, 2025

Conversation

lukinovec
Copy link
Contributor

@lukinovec lukinovec commented Feb 10, 2025

This PR makes the UrlGeneratorBootstrapper and the TenancyUrlGenerator clearer and overall more useful (e.g. simplifies using Ziggy's route() helper with path identification, in response to #1302, note: update Ziggy route() integration documentation for both the path and the query string identification).

UrlGeneratorBootstrapper

The route() helper receives the tenant parameter automatically. This is achieved by adding the tenant parameter to URL::defaults() in UrlGeneratorBootstrapper.

This behavior can be disabled by setting UrlGeneratorBootstrapper::$addTenantParameterToDefaults to false.

TenancyUrlGenerator

The TenancyUrlGenerator now

  • doesn't pass the tenant route parameter by default
  • doesn't prefix the route names passed to route() by default

TenancyUrlGenerator is intended to be configured in two cases:

  1. when using path identification, configure it for prefixing names passed to the Laravel route() helper with the tenant. prefix automatically (set the static $prefixRouteNames property to true)
  2. when using query string identification, configure it for passing the tenant query parameter (set the static $passTenantParameterToRoutes to true -- this is needed with query string identification, since URL::defaults() only works for route parameters)

With path identification, you can also opt out of adding the tenant parameter to the defaults by setting UrlGeneratorBootstrapper::$addTenantParameterToDefaults to false and make TenancyUrlGenerator pass the tenant parameter instead by setting TenancyUrlGenerator::$passTenantParameterToRoutes to true (e.g. in TenancyServiceProvider).

The UrlGeneratorBootstrapper tests are also simplified and updated accordingly.

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.71%. Comparing base (25360f6) to head (53ea46a).
Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1311      +/-   ##
============================================
+ Coverage     84.67%   84.71%   +0.03%     
- Complexity     1054     1056       +2     
============================================
  Files           177      177              
  Lines          3086     3094       +8     
============================================
+ Hits           2613     2621       +8     
  Misses          473      473              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lukinovec lukinovec changed the title [4.x] Pass tenant parameter using defaults() in UrlGeneratorBootstrapper [4.x] Add tenant parameter to defaults() in UrlGeneratorBootstrapper Feb 10, 2025
@lukinovec lukinovec marked this pull request as ready for review February 10, 2025 12:54
@stancl stancl merged commit cecf07a into master Feb 14, 2025
11 checks passed
@stancl stancl deleted the url-generator-override-update branch February 14, 2025 12:57
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.

InertiaJS router does not seem to work correctly with Path Identification
2 participants