I've come across a very unusual bug that happens only on our staging server.
Here is part of my routes.php file
Route::post('posts/add', [PostController::class, 'batchAdd'])->name('posts.batch-add');
Route::resource('posts', PostController::class)->only('show', 'update', 'destroy');
When we try to hit /posts/add endpoint, we get 404 response:
{
code: 404,
details: "No query results for model [App\\Models\\Post] add",
message: "Record not found",
}
Laravel is trying to bind here "add" to Post model. Thing that is very interesting is that we don't have this issue on production or local environments. It works everywhere except on staging server. On every build, we run this command to completely clear everything:
php artisan route:clear &&
sudo php artisan cache:clear &&
php artisan config:clear &&
php artisan view:clear &&
php artisan event:clear &&
php artisan clear-compiled &&
php artisan optimize:clear &&
php artisan route:cache
Everything works completely fine on both the production and local environments.
Things we tried:
- Delete vendor and storage, and reinstalling everything with composer
- Zipped the whole production folder, copied it to staging server, changed environment variables
But we still get the same issue. Difference in environment variables is credentials for DB, APIs, and APP_ENV.
Anyone came across similar issue?