DEV Community

Ariel Mejia
Ariel Mejia

Posted on

Laravel get route name from given URL

A common use case for a tabs component is to check if a routes as strings is the current route or if it exists in your app.

Laravel Route facade allows to expose the route object easily to check this:

Using the route name
$route = route('users.index');

Route::getRoutes()->match($route);
Enter fullscreen mode Exit fullscreen mode
Using a string
$url = 'https://your-app.com/users';

Request::create($url)
Enter fullscreen mode Exit fullscreen mode

Hope that the tip is useful!

Top comments (0)