【发布时间】:2017-10-02 12:28:44
【问题描述】:
通过提供一个 URL,我想知道是否有任何方法可以确定我的 Laravel 应用程序中是否存在该 URL(与想要检查外部 URL 的“How can I check if a URL exists via 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
}
【问题讨论】:
-
你能回显
$request吗? -
是的,它为我提供了请求标头:
GET /exists HTTP/1.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Accept-Language: en-us,en;q=0.5 Host: localhost User-Agent: Symfony/3.X -
这似乎是正确的,您确定路线已经存在吗?你能转储
$routes吗?
标签: php laravel routes laravel-5.4