简体   繁体   中英

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. So, I'm working locally using laragon and I already have my project installed on 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. 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.

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? So how can I fix this?

My RouteServiceProvider

api.php my API routes

web.php my Web routes

The problem! the route checks web routes first before it checks in api!

Now I change route in web routes. not the same routes anymore and i check postman again

It works fine if not match in web routes!

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. Solved by setting 'domain' => 'example.test' in fortify config file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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