简体   繁体   English

Laravel API 子域上的路由在 web 之前路由到 go 到 api 路由

[英]Laravel API routes on subdomain are routing on web before they go to api routes

I'm trying to implement laravel api through a subdomain not a prefix.我正在尝试通过子域而不是前缀来实现 laravel api。 So, I'm working locally using laragon and I already have my project installed on example.test.所以,我在本地使用 laragon 工作,我已经在 example.test 上安装了我的项目。 Then I went to vhosts and added a record to relate api.example.test to 127.0.0.1 as the same domain.然后我去了 vhosts 并添加了一条记录,将 api.example.test 与 127.0.0.1 关联为同一域。 Then I Added my RouteServiceProvider to update the api routes and make it use domain ('api.example.test') to redirect routes to my api.php file.然后我添加了我的 RouteServiceProvider 以更新 api 路由并使其使用域('api.example.test')将路由重定向到我的 api.php 文件。

The problem is: All routes to api.example.test are firstly going through web routes then if didn't find any match it goes to api routes and try to match?问题是:到 api.example.test 的所有路由都首先经过 web 路由然后如果没有找到任何匹配它去 api 路由并尝试匹配? So how can I fix this?那么我该如何解决呢?

My RouteServiceProvider我的路由服务提供商

api.php my API routes api.php 我的 API 路线

web.php my Web routes web.php 我的 Web 路线

The problem!问题! the route checks web routes first before it checks in api!该路线在检查 api 之前首先检查 web 路线!

Now I change route in web routes.现在我在 web 路线中更改路线。 not the same routes anymore and i check postman again不再是相同的路线,我再次检查 postman

It works fine if not match in web routes!如果在 web 路线中不匹配,它可以正常工作!

any solutions would be appreciated!任何解决方案将不胜感激!

Already solved!已经解决了! The problem was with my fortify configuration as I set it to have a prefix for localization {locale} and due to fortify routes aren't in routes web file I think it hooks them to service provider so API routes were going to fortify first.问题出在我的强化配置上,因为我将它设置为具有本地化{locale}的前缀,并且由于强化路由不在路由 web 文件中,我认为它会将它们挂接到服务提供商,因此 API 路由将首先进行强化。 Solved by setting 'domain' => 'example.test' in fortify config file.通过在强化配置文件中设置'domain' => 'example.test'解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM