Created
November 25, 2020 10:41
-
-
Save ponich/9b5b6aaa35ed6ce54670731219b6d820 to your computer and use it in GitHub Desktop.
laravel
This file contains hidden or 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 | |
| if (!function_exists('getRouteUriByName')) { | |
| /** | |
| * Get route URI by route name | |
| * | |
| * @param string $name | |
| * @return string | |
| * @throws Exception | |
| */ | |
| function getRouteUriByName(string $name): string | |
| { | |
| /** | |
| * @var RouteCollection $routes | |
| */ | |
| $routes = app('router')->getRoutes(); | |
| /** | |
| * @var Route|null $router | |
| */ | |
| $router = $routes->getByName($name); | |
| if (!$router) { | |
| throw new \Exception("Could not find route by name `{$name}`"); | |
| } | |
| return Str::before($router->uri(), '{'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment