php - Laravel 从给定的 URL 获取路由
问题描述
拉拉维尔。如何从给定的 URL 获取路由。我知道这个答案:https ://stackoverflow.com/a/36476224/9696145
这种方式对我没有帮助,因为如果您设置错误的 URI,我的应用程序出于某种原因返回 404 视图。我只需要返回类似 null 的东西
解决方案
https://laracasts.com/discuss/channels/laravel/how-to-get-a-route-from-uri
try {
$url = 'url';
$route = app('router')->getRoutes()->match(app('request')->create($url))
} catch (NotFoundHttpException $e) {
$route = null;
}
在非获取路线的情况下:
$method = 'POST';
$url = 'url';
$route = app('router')->getRoutes()->match(app('request')->create($url , $method))
推荐阅读
- node.js - 如何在 Angular 问题中获得一条记录?
- java - 为什么我不能从 VideoView 播放我的视频?
- database - openlayers 中的 WFS 层未显示在数据库中
- javascript - SCSS 脚本构建
- java - Mockito when...return 在 setUp 方法中的子句
- azure - Azure devops 管道任务错误:Measure-Command 调用失败
- reactjs - 如何在打字稿中编写带有参数化道具和前向引用的 React 组件
- php - 不正确的整数值:laravel 7 中第 1 行的列的“[]”
- asp.net-mvc - 如何在每列后添加新行以输出 api mvc 控制器代码?
- javascript - 如果我有一个 React 前端和一个微服务后端,我可以有两个部署目标(S3 用于前端,EKS 用于后端)吗?