Created
October 23, 2023 21:32
-
-
Save anaxamaxan/ecd96674d58477b0299700e6aadd6832 to your computer and use it in GitHub Desktop.
Laravel Route Name from URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function routeNameFromUrl(string $url, string $method = 'GET'): ?string | |
{ | |
$method = strtoupper($method); | |
$request = app('request') | |
->create(trim($url), $method); | |
return app('router') | |
->getRoutes() | |
->match($request) | |
->getName(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment