---
title: "Discussion on \"Adding a Laravel backend to a Remix App\" | Hashnode"
description: "Discussion on \"Adding a Laravel backend to a Remix App\". Or How I Learned to Stop Worrying and Love PHP"
url: "https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Adding a Laravel backend to a Remix App](https://davecalnan.blog/adding-a-laravel-backend-to-a-remix-app?utm_source=hashnode&utm_medium=feed)

Or How I Learned to Stop Worrying and Love PHP

Jun 14, 2022 · 9 min read · davecalnan.blog  
Read the article

-   [#remix](https://hashnode.com/tag/remix)
-   [#laravel](https://hashnode.com/tag/laravel)
-   [#prisma](https://hashnode.com/tag/prisma)
-   [#reactjs](https://hashnode.com/tag/reactjs)

## Written by

[Dave Calnan](https://hashnode.com/@davecalnan)

@davecalnan

  
[View profile](https://hashnode.com/@davecalnan)

Software Engineer figuring it out

## Responses 5

Markdown supported · ⌘↵ to post

[Xiaojun Deng](https://hashnode.com/@hktang)

[Feb 17, 2024](https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798/comment/65d09ee6069b831829760c24)

Thanks for sharing! I am considering switching from React/Inertia to Remix. As I understand it, the first loader call is from the server side. How do we get information about the authed user, for example if I want the middleware to check authentication/authorisation before serving the api results?

[Luke Martin](https://hashnode.com/@lukemartin)

[Oct 27, 2023](https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798/comment/653b598799e256838d60981c)

Do you serve the Laravel app on a subdomain?

In the Remix + Laravel example, both the route and api are served under `GET /users`, presumably because it’s just example code.

Curious how you have these running side by side for real.

Thanks 🙏

[Dave Calnan](https://hashnode.com/@davecalnan)

[Oct 28, 2023](https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798/comment/653b598799e256838d60981c#reply-653d9d5d8bb1c48f931a2af0)

They’re both on subdomains in my instance - so app.example.com and api.example.com.

For another project, I have deployed this architecture to a single server via Laravel Forge. The Remix web app is available at the root domain via an nginx reverse proxy to port 3000. The Laravel backend is only accessible over localhost on that server so the Remix backend makes calls to localhost:8000 on that same server.

That works fine for smaller projects where you don’t need to access the Laravel backend outside of the Remix backend.

[Jaska](https://hashnode.com/@jaskajanis)

[Jan 24, 2023](https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798/comment/63cf8bc91819c3d44449cca5)

Nicely written guide, thanks. But as a seasoned programmer, I'm a bit worried about writing the backend code twice. In the pure remix code you access the database directly with Prisma and in the PHP backend you do it again using Laravel.

In real life you usually have more complicated business logic on your server. You might write an audit log entry for each GET request or have some other side effects on the server. That's why you write actions/operations on your backend only once so that none of the business logic rules are forgotten.

So wouldn't I need to write all the backend using remix/javascript OR always make API calls from the remix backend loaders?

[Dave Calnan](https://hashnode.com/@davecalnan)

[Mar 5, 2023](https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798/comment/63cf8bc91819c3d44449cca5#reply-6404875287595bb6fc8849ee)

Hi [Jaska](https://hashnode.com/@jaskajanis),

I'm sorry if the article wasn't clear!

The examples in this article of Remix talking to the database directly were how I did things before adding the Laravel backend. Now the all the Remix loaders do is call the API for my Laravel backend.

So I only write the backend code once for exactly the reasons you mentioned.

Hopefully that clears things up!

[Mykolas Mankevicius](https://hashnode.com/@TheMykolas)

[Sep 22, 2022](https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798/comment/632c1e19e06c24f9f23a3d71)

Do you have an example of how you setup the api.post stuff?

[Dave Calnan](https://hashnode.com/@davecalnan)

[Sep 26, 2022](https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798/comment/632c1e19e06c24f9f23a3d71#reply-63315f874dd8b2344a768860)

I actually extracted this into its own npm package:

[github.com/davecalnan/typesafe-api/tree/main/pack…](https://github.com/davecalnan/typesafe-api/tree/main/packages/typesafe-api-client)

```
yarn add @davekit/typesafe-api-client
```

It's basically just:

```
export const api = createApiClient({
  baseUrl: "your-app.com/api"
});

const result = api.get("/some-path");

const onClick = () => api.delete("/some-other-path");
```

I pair it with `@davekit/typesafe-api` and generate types for all my backend routes that I can then import into the frontend and get type-safety over the API. But that needs a whole blog post of its own to get into.

[Micheal Mand](https://hashnode.com/@mikemand)

[Jun 20, 2022](https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798/comment/62b0bccf5abe3c6b79d140ef)

If you don't need the features of a controller (the only one I can really think of is common middleware per Controller, but you can do the same thing with a route group), you can use Closures in your routes. Since Laravel 8 there is no impact on route caching and it eliminates half the code you have to write in Laravel.

I have slowly gotten rid of using Controllers for things that don't need a controller, like getting all users (hopefully you plan to paginate this, or already have and just simplified it for this blog post?) or displaying a simple view (Route::view is my best friend for all of those required static pages like Policies, Terms & Conditions, etc.

[Dave Calnan](https://hashnode.com/@davecalnan)

[Jun 20, 2022](https://hashnode.com/posts/adding-a-laravel-backend-to-a-remix-app/62a874fa0baf4306d9493798/comment/62b0bccf5abe3c6b79d140ef#reply-62b0e4895abe3c6b79d1457c)

Route::view() is great! I also really like closures for simple stuff just like that e.g. a health check endpoint that just needs to return a 200 OK.

In my actual controllers I would paginate and use Form Requests/JSON Resources, authorisation etc - just wanted to keep that example simple and comparable to the Prisma one!
