Search code examples
laravellaravel-8http-status-code-404laravel-routinglaravel-sail

Laravel - 404 on some routes - only on local (Sail)


Pulling my hair out with this one.

I have an API that is working completly in both staging and production environments but recently has started return some 404 on two of the routes locally, and I cant work out why. (No changes have been made to the site locally).

Below is the affected route group:

Route::group(['middleware' => ['api.auth']], function () {

Route::post('role_update', 'App\Http\Controllers\MobileApi@role_update');
Route::post('request_items', 'App\Http\Controller\MobileApi@request_items');
Route::post('download_log', 'App\Http\Controllers\MobileApi@download_log');
Route::post('log_time', 'App\Http\Controllers\MobileApi@log_time');
Route::post('log_search', 'App\Http\Controllers\MobileApi@log_search');

});

The role_update & log_time routes return 404 locally and run perfectly in production and in the staging environment.

All of these routes are shown as generated on route:list.

I have run route:clear & route:cache & route:optimize to no beneficial effect.

I know that the methods are rechable on the controller and that the middleware isnt the issue as if I use one of the working routes URI's to call one of the non working route methods it works. For example, if I switch things around so that a post to download_log actually points to the role_update method the 404 disappears.

Interestingly I cannot change the URI's of any of these routes or they immediatly start throwing 404's even when confirmed that they are registered in route:list. I also can't add any new routes as they all throw 404's.

This makes me suspicious that the routes are being cached and not overridden somewhere?

My local environment is laravel sail - there has been no updates between this working and not working.

Laravel version - 8.30.1

Any help with this would be greatly appretiated.

Thanks

N.B - we have also just noticed that the role_update route is actually returning a 404 on the production and staging servers but only from our android application - its working on both iOS and postman. Very odd.


Solution

  • For anyone finding this - I am the issue - I very stupidly forgot one of the variables required to access the API - to add to my stupidity, during testing I had the API throwing 404's if that variable was missing.

    The reason it was working on some environments and not others is that my postman requests had the required variable in them just by chance! Obviously this would usually throw and error that I could work out be I had forced it to be 404's during development.

    Sorry for any time taken thinking about this!