It seems like the issue you're encountering is related to how JavaScript is interpreting the start and end variables when you're trying to pass them in the URL. The [object Object] output suggests that start and/or end might not be simple string variables as you expect, but rather objects or the result of an expression that isn't being evaluated to a string.
Here's a step-by-step solution to ensure that the date strings are passed correctly:
- Make sure that
startandendare indeed strings in theYYYY-MM-DDformat. You can log them to the console just before the request to verify their values.
console.log(start); // Should be a string like "2023-08-01"
console.log(end); // Should be a string like "2023-08-31"
- If
startandendare not strings, you'll need to convert them to strings. If they areDateobjects, you can use thetoISOString()method and then slice the string to get theYYYY-MM-DDpart.
let startDateString = start.toISOString().slice(0, 10);
let endDateString = end.toISOString().slice(0, 10);
- Use the string variables in the URL for the GET request.
router.get(`/admin/reports/nra/export/${startDateString}/${endDateString}`)
- If you're still encountering issues, it might be due to Vue/Inertia's
router.getmethod not being used correctly. Inertia.js typically uses theInertia.visitmethod for navigation. If you're using Inertia, the correct way to make a GET request with parameters would be:
Inertia.visit(`/admin/reports/nra/export/${start}/${end}`, {
method: 'get'
});
-
If you're using Vue Router, ensure that you're using the correct method to navigate or make a request. For navigation, you would use
this.$router.pushorthis.$router.replace. -
Lastly, ensure that there are no URL encoding issues. Special characters in URL parameters should be encoded. JavaScript's
encodeURIComponentfunction can be used for this purpose.
let encodedStart = encodeURIComponent(start);
let encodedEnd = encodeURIComponent(end);
router.get(`/admin/reports/nra/export/${encodedStart}/${encodedEnd}`)
By following these steps, you should be able to pass the date strings correctly to your Laravel controller. If the problem persists, double-check the values of start and end and how they are being handled in your Vue/Inertia application.