I have my Laravel 9 installed inside xampp/htdocs. It works fine when I use API URL with localhost but it throws 404 when I use my device's IP address.
http://localhost/myapp/public/api/users
It works fine and returns me all the users
but
http://192.168.254.6/myapp/public/api/users
gives me 404. Due to this I am not able to access the app from local network too.
I simply tested the case with only one php file test.php
and http://192.168.254.6/testapp/test.php
works fine.
I logged the incoming requests in index.php inside Laravel public directory and I found that Laravel is receiving the requests but when I tried to log the requests inside a controller and even inside a middleware, I got nothing.
What might be the reason for it?
After long research, I found the solution. The issue was due to a package configuration file config/tenancy.php
of https://tenancyforlaravel.com/
The old configuration was:
/**
* The list of domains hosting your central app.
*
* Only relevant if you're using the domain or subdomain identification middleware.
*/
'central_domains' => [
'127.0.0.1',
'localhost',
],
Adding the specific local IP or a blank string fixed the issue:
/**
* The list of domains hosting your central app.
*
* Only relevant if you're using the domain or subdomain identification middleware.
*/
'central_domains' => [
'127.0.0.1',
'localhost',
''
],
As stated in the code comments, this config should have been only valid while using domain or subdomain but I was using request data to identify tenant, still it was causing the issue.