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?
My Answer:
There could be a few reasons why your Laravel API is not working with your device's IP address:
1. Check your .htaccess file: Make sure that your .htaccess file is configured correctly to allow access from external IP addresses. You may need to update the RewriteBase directive to reflect your device's IP address.
2. Check your virtual host configuration: If you are using Apache, make sure that your virtual host configuration is set up to allow access from external IP addresses. You may need to update the ServerName and ServerAlias directives to include your device's IP address.
3. Check your firewall settings: Your firewall may be blocking incoming requests from external IP addresses. Make sure that your firewall is configured to allow traffic on the port that your Laravel API is running on.
4. Check your Laravel routing configuration: Make sure that your routes are configured correctly to handle requests from external IP addresses. Check your RouteServiceProvider and web.php files to ensure that your routes are set up correctly.
5. Check your CORS configuration: If you are making requests from a different domain or IP address, you may need to configure CORS (Cross-Origin Resource Sharing) settings in your Laravel application to allow requests from external sources.
By checking these potential issues, you should be able to troubleshoot why your Laravel API is not working with your device's IP address.
Rate this post
4 of 5 based on 5398 votesComments