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 current url resolver to sites #9098

Merged
merged 6 commits into from
Dec 7, 2023
Merged

[4.x] Add current url resolver to sites #9098

merged 6 commits into from
Dec 7, 2023

Conversation

ajnsn
Copy link
Contributor

@ajnsn ajnsn commented Dec 1, 2023

When using Livewire components within multisite I noticed that it's not to easy to rely on the Site::current() because the current() relies on the request()->getUri(). In Livewire's subsequent requests this is not the original url which results typically in resolving the default site.

This PR adds the possbility to provide a callback to allow custom url resolution for current().

This could be used in a SeviceProvider using Livewire 3 likes this:

use Statamic\Facades\Site;

Site::resolveCurrentUrl(fn () => Livewire::originalUrl());

@ajnsn ajnsn changed the title Add currentUrlCallback to Sites [4.x] Add currentUrlCallback to Sites Dec 1, 2023
Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool idea.

Could you make it non-static?

If you do Statamic\Facades\Site::resolveCurrentUrl() it'll call the resolveCurrentUrl in this class in a non-static way.

The Site (singular) facade calls the Sites (plural) class.

@ajnsn ajnsn changed the title [4.x] Add currentUrlCallback to Sites [4.x] Add currentUrlCallback to Site Dec 5, 2023
@ajnsn ajnsn requested a review from jasonvarga December 5, 2023 06:53
@jasonvarga jasonvarga changed the title [4.x] Add currentUrlCallback to Site [4.x] Add current url resolver to sites Dec 7, 2023
Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I've renamed it to resolveCurrentUrlUsing to better fit with some Laravel conventions.

e.g. https://github.com/laravel/framework/blob/88d6037dcda4f5696b85ce24ad11ff7e97fd14f0/src/Illuminate/Auth/AuthManager.php#L261-L266

@jasonvarga jasonvarga merged commit ed8885e into statamic:4.x Dec 7, 2023
19 checks passed
@ajnsn ajnsn deleted the resolve-current-url branch December 7, 2023 19:58
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.

2 participants