小编Dev*_*vid的帖子

Laravel 检查给定 url 的路由是否存在于路由内

通过提供 URL,我想知道是否有任何方法可以确定该 URL 是否存在于我的 Laravel 应用程序中(与想要检查外部 URL 的“如何通过 Laravel 检查 URL 是否存在? ”相比)?

我尝试了这个,但它总是告诉我网址不匹配:

$routes = \Route::getRoutes();
$request = \Request::create('/exists');
try {
    $routes->match($request);
    // route exists
} catch (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e){
    // route doesn't exist
}
Run Code Online (Sandbox Code Playgroud)

php routes laravel laravel-5.4

10
推荐指数
3
解决办法
2万
查看次数

标签 统计

laravel ×1

laravel-5.4 ×1

php ×1

routes ×1