Laravel get route name from given URL
laravel, php, routes
Solution
A very easy way to do it `Laravel 5.2`
app('router')->getRoutes()->match(app('request')->create('/qqq/posts/68/u1'))->getName()
It outputs my Route name like this `slug.posts.show`
Update: For method like POST, PUT or DELETE you can do like this
app('router')->getRoutes()->match(app('request')->create('/qqq/posts/68/u1', 'POST'))->getName()//reference https://github.com/symfony/http-foundation/blob/master/Request.php#L309
Also when you run `app('router')->getRoutes()->match(app('request')->create('/qqq/posts/68/u1', 'POST'))` this will return `Illuminate\Routing\Route` instance where you can call multiple useful public methods like `getAction`, `getValidators` etc. Check the source https://github.com/illuminate/routing/blob/master/Route.php for more details.
Problem
In Laravel, we can get route name from current URL via this: ``` Route::currentRouteName() ``` But, how can we get the route name from a specific given URL? Thank you.