{"id":19543871,"url":"https://github.com/benjpaddock/livewire-urls","last_synced_at":"2025-07-19T04:03:32.013Z","repository":{"id":254326840,"uuid":"846201062","full_name":"benjpaddock/livewire-urls","owner":"benjpaddock","description":"Get the previous and current url in Livewire.","archived":false,"fork":false,"pushed_at":"2025-01-27T20:10:25.000Z","size":469,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T05:34:47.305Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benjpaddock.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-22T18:11:53.000Z","updated_at":"2024-08-22T18:49:09.000Z","dependencies_parsed_at":"2024-11-11T06:00:22.785Z","dependency_job_id":null,"html_url":"https://github.com/benjpaddock/livewire-urls","commit_stats":null,"previous_names":["benjpaddock/livewire-urls"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/benjpaddock/livewire-urls","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjpaddock%2Flivewire-urls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjpaddock%2Flivewire-urls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjpaddock%2Flivewire-urls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjpaddock%2Flivewire-urls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benjpaddock","download_url":"https://codeload.github.com/benjpaddock/livewire-urls/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjpaddock%2Flivewire-urls/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265887084,"owners_count":23844339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T03:22:51.351Z","updated_at":"2025-07-19T04:03:31.993Z","avatar_url":"https://github.com/benjpaddock.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![livewire-urls](https://github.com/ralphjsmit/livewire-urls/blob/main/docs/images/livewire-urls.jpg)\n\n# Get the current and previous url in Livewire.\n\nThis package gives you a simple way to **retrieve the current and previous URL** in Livewire.\n\nUnfortunately, 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()-\u003ecurrent()` **point to an internal Livewire** route, instead of the **\"real route\" your user is on**.\n\nThis package provides you with a middleware and **helper methods to determine which URL is currently being used**.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require ralphjsmit/livewire-urls\n```\n\nNext, you should add `\\RalphJSmit\\Livewire\\Urls\\Middleware\\LivewireUrlsMiddleware::class,` to your Http `Kernel.php`, in the `web` key of the `$middlewareGroups` property.\n\n## Usage\n\n### Current url\n\n```php\nuse RalphJSmit\\Livewire\\Urls\\Facades\\Url;\n\n$currentUrl = Url::current();\n```\n\n### Current route\n\n```php\n$currentRouteName = Url::currentRoute();\n```\n\nThe `Url::currentRoute()` returns `null` when the user is on a route without a name.\n\n### Previous url\n\n```php\n$previousUrl = Url::previous();\n```\n\nThe `Url::previous()`-method returns `null` when there isn't a previous route available.\n\n### Previous route\n\n```php\n$previousRouteName = Url::previousRoute();\n```\n\nThe `Url::previousRoute()` returns `null` when there isn't a previous route or if the previous route wasn't a named route.\n\n### Last recorded url\n\nYou can use the `Url::lastRecorded()` method to get the last url from the history that is _different_ from the current url.\n\nFor example:\n\n1. User visits page A\n2. User visits page B\n3. User visits page B\n\nThe `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.\n\n```php\n$lastRecordedUrl = Url::lastRecorded();\n```\n\n### Last recorded route\n\nYou can use the `Url::lastRecordedRoute()` method to get the last route from the history that is _different_ from the current url/route.\n\n```php\n$lastRecordedRoute = Url::lastRecordedRoute();\n```\n\nThe `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.\n\n## General\n\n🐞 If you spot a bug, please submit a detailed issue and I'll try to fix it as soon as possible.\n\n🔐 If you discover a vulnerability, please review [our security policy](../../security/policy).\n\n🙌 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!\n\n🙋‍♂️ [Ralph J. Smit](https://ralphjsmit.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjpaddock%2Flivewire-urls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenjpaddock%2Flivewire-urls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjpaddock%2Flivewire-urls/lists"}