Download the PHP package ralphjsmit/livewire-urls without Composer
On this page you can find all versions of the php package ralphjsmit/livewire-urls. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ralphjsmit/livewire-urls
More information about ralphjsmit/livewire-urls
Files in ralphjsmit/livewire-urls
Package livewire-urls
Short Description Get the previous and current url in Livewire.
License MIT
Homepage https://github.com/ralphjsmit/livewire-urls
Informations about the package livewire-urls
Get the current and previous url in Livewire.
This package gives you a simple way to retrieve the current and previous URL in Livewire.
Unfortunately, Laravel or Livewire cannot handle this for you, since Livewire also makes requests to your server when a user interacts with your webpage. This means that the usual methods like URL()->current()
point to an internal Livewire route, instead of the "real route" your user is on.
This package provides you with a middleware and helper methods to determine which URL is currently being used.
Installation
You can install the package via composer:
Next, you should add \RalphJSmit\Livewire\Urls\Middleware\LivewireUrlsMiddleware::class,
to your Http Kernel.php
, in the web
key of the $middlewareGroups
property.
Usage
Current url
Current route
The Url::currentRoute()
returns null
when the user is on a route without a name.
Previous url
The Url::previous()
-method returns null
when there isn't a previous route available.
Previous route
The Url::previousRoute()
returns null
when there isn't a previous route or if the previous route wasn't a named route.
Last recorded url
You can use the Url::lastRecorded()
method to get the last url from the history that is different from the current url.
For example:
- User visits page A
- User visits page B
- User visits page B
The Url::lastRecorded()
would give you the url of page A. The function returns null
when there isn't an other url found, apart from the current session.
Last recorded route
You can use the Url::lastRecordedRoute()
method to get the last route from the history that is different from the current url/route.
The Url::lastRecordedRoute()
would give you the route of page A from the previous example, if page A is on a named route. Otherwise, it would return null
. The function also returns null
when there isn't an other url found, apart from the current session.
General
🐞 If you spot a bug, please submit a detailed issue and I'll try to fix it as soon as possible.
🔐 If you discover a vulnerability, please review our security policy.
🙌 If you want to contribute, please submit a pull request. All PRs will be fully credited. If you're unsure whether I'd accept your idea, feel free to contact me!
🙋♂️ Ralph J. Smit
All versions of livewire-urls with dependencies
illuminate/contracts Version ^8.83|^9.0|^10.0|^11.0|^12.0
livewire/livewire Version ^2.10|^3.0
spatie/laravel-package-tools Version ^1.9.2