Reputation: 1315
I have some trouble with Laravel and Ajax that I haven't been able to Google or Stackoverflow my way out of. Whatever solutions I've seen, I've already accounted for.
Sporadically I'm getting a 500 error (sometimes it's 401). It only happens with Ajax, which would indicate that I don't properly send the CSRF token.
But the CSRF is on every page load, and the issue started 4 days ago, while the project is around a month old. It happens maybe 1 in 10 Ajax calls. The other 9 will execute just fine.
The Ajax call comes instantly after page load. Is it possible that Laravel somehow has not updated its expectations for the incoming Ajax call? No other Ajax calls cause this issue.
The laravel.log says:
production.ERROR: No application encryption key has been specified. {"exception":"[object] (RuntimeException(code: 0): No application encryption key has been specified. at C:\\....\\vendor\\laravel\\framework\\src\\Illuminate\\Encryption\\EncryptionServiceProvider.php:42)
[stacktrace]
Which is super weird to me for two reasons. First of all, an encryption exists. As mentioned the project has existed for a long time and the issue is sporadic. Secondly, it says "production.ERROR" but the environment is local. I have this in the .env file:
APP_ENV=local
Does anybody have any ideas on how to resolve or how to further debug the issue? I'm at a bit of a blank here.
UPDATE: The issue is definitely related to AJAX calls invoked immediately on page load. I've just had the exact same issue occur in a different project, with all other AJAX calls in the project working like they're supposed to; But the one invoked immediately on page load fails with 401 and 500 sporadically.
Upvotes: 0
Views: 493
Reputation: 547
For anybody who may still be having this problem, try this:
php artisan config:clear
Upvotes: -1