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 🙏
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?
Do you have an example of how you setup the api.post stuff?
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.
Xiaojun Deng
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?