To fetch data from a different endpoint without changing the URL in Inertia.js, you can use the Inertia.get method. This method allows you to make an AJAX request to a specific endpoint and retrieve the data without changing the URL.
In your case, you can modify your component to use Inertia.get to fetch logs for a specific job. Here's an example of how you can achieve this:
// Import the Inertia object
import { Inertia } from '@inertiajs/inertia';
// Inside your component's method
fetchLogs(jobId) {
Inertia.get(`/logs/job/${jobId}`).then(response => {
// Handle the response data here
console.log(response);
}).catch(error => {
// Handle any errors here
console.error(error);
});
}
In this example, fetchLogs is a method that takes the jobId as a parameter and makes an AJAX request to the /logs/job/{id} endpoint using Inertia.get. You can then handle the response data or any errors as needed.
Remember to replace console.log(response) with the logic to update your component's state or perform any other actions with the fetched data.
Additionally, you can consider changing your endpoint to /jobs/{id}/logs if it makes more sense in your application's context. This can help improve the readability and maintainability of your code.
Using axios is also a valid option for making AJAX requests in this scenario. However, since you are already using Inertia.js, it's recommended to use the built-in Inertia.get method to maintain consistency within your application.
I hope this helps! Let me know if you have any further questions.