We are using Laravel 9 + Inertia + VueJs 3 in our project. Recently, we encountered an issue where new routes are not working on a new DigitalOcean droplet, although they work fine on our local environments and other DigitalOcean droplets. The new droplet was created using the same template as the other droplets for this application.
Steps to Reproduce:
The issue was noticed after deploying the latest code. While older routes continue to work fine, new routes are failing to function. Here’s how we figured it out:
1.Action "Save" should make a request to the API:
const saveSelection = () => {
axios
.post(route('clinician.set-device'), {
use_case_setting_id: deviceSlotId.value,
device_data: devices.value[selectedOption.value],
})
.then(() => {
...
};
2.However, as shown in picture, the request does not occur, and no errors are logged in the browser console:
3.We decided to run the Vue application in "watch"-mode on the server. Upon doing so, we saw the following error in the console:
Uncaught Error: Ziggy error: route ‘clinician.set-device’ is not in
the route list.
4.Using php artisan route:list
, we confirmed that the route exists on the server:
5.We tried clearing the Laravel cache with the following commands: php artisan cache:clear && php artisan route:clear && php artisan config:clear && php artisan view:clear
. However, the result remained the same.
Next, we replaced the route with a direct link and received a 404 response:
const saveSelection = () => {
axios
.post('/api/clinician/set-device', {
use_case_setting_id: deviceSlotId.value,
device_data: devices.value[selectedOption.value],
})
.then(() => {
...
};
We then checked the existing API routes, and everything worked as expected:
Finally, we added a new test route to routes/api.php file. It appeared in the general route list but still returned a 404:
Route::get('test', function () {
return response()->json(['message' => 'Hello World!']);
});
Question
Why are the old routes and URLs working, but the new ones are not?
2
Answers
The problem was a routes names conflict:
Don't forget to use the
php artisan optimize
utility, it can be very useful in such cases.Can you please re-verify the API route group on RouteServiceProvider, and run below command
php artisan optimize:clear