Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

amir5's avatar
Level 7

How to get valid livewire current url

I have a livewire component that has a bunch of props that are also url query strings, and I want to store the url in session whenever user changes them(on render), but when I use URL::full() I get livewire's update url instead of actual final url.

2 likes
7 replies
s4muel's avatar

either try

request()->fullUrlWithQuery(request()->query());

or build the url from your livewire properties

url()->current() . '?' . http_build_query($arrayFromYourProperties);

amir5's avatar
Level 7

@s4muel The problem is, when livewire sends update request, the url()->fullUrl returns /livewire/update.

Now I'm storing those props invidually in user session, and reloading them.

s4muel's avatar

@amir5 build your own url then (as in the second part of my answer), if you have just a couple of props, shouldn't be too messy

Christofer's avatar

@s4muel Nope, doesn't work either.

url()->current() . '?' . http_build_query($array); // also returns a url containing "livewire/update"

malinda7's avatar

Livewire’s AJAX behavior means url()->current() will point to /livewire/message/... instead of your real page URL. A simple fix is to capture it once in mount()—like public $currentUrl; public function mount() { $this->currentUrl = url()->current(); }—and then use $currentUrl later.

If you want both current and previous URLs, there's a neat package called ralphjsmit/livewire-urls. It adds middleware that tracks these for you and gives you helper methods like Url::current() and Url::previous() that actually reflect the real page URLs.

Either way, you're covered—use either the mount() trick for a quick win or go with the package for full URL tracking.

Please or to participate in this conversation.