Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

liamseys's avatar

Laravel Breeze + NextJS API Call

Hello

I'm using the starter kit provided by Laravel for a backend powered by Laravel and frontend NextJS. I'm using the following snippet to make an API call to my backend hosted on localhost:8000

export async function getStaticProps() {
    const response = await axios.get('/products');

    return {
        props: {
            products: response.data.data
        },
    }
}

When trying to visit the page I receive the following error:

Error: connect ECONNREFUSED ::1:8000

Login, registration and password reset all just work fine. Does anyone have an idea?

0 likes
2 replies
jlrdw's avatar

If using artisan serve, try changing to an actual server, apache or nginx.

pscully's avatar

I found for local development with this setup what I've had to do is run a localhost server and use axios for login, registration - those items that come out of the box, basically leave those as is. When using the provided axios implementation inside getServerSideProps in my Nextjs page I was getting the exact same error. Based on the response above by @jlrdw I set up Valet and used fetch() with the full local testing domain. If I switched everything to using the Valet .test domain then I get CORS related errors when logging in and registering. Not the ideal setup to use both but it does work if you want to code instead of troubleshoot.

Please or to participate in this conversation.