I'm currently learning inertia with react after using livewire and finding myself quite limited so I'm making a sample project that makes invoices to practice making forms and saving data to a database. Currently I want to make a form where the user can input data about the service the invoice is for, the client and the person providing the service, all of which are different models with their own tables, and save it all in one go. All the tutorials I could find only work with one model and there was one that had one gigantic component which I'd very much like to avoid having. Any recommendations?

2 Replies 2

I've used Inertia + React professionally for many years so I think I can help you here.

So you have 2 questions here basically, and please correct me if I misunderstood:

  1. How to save multiple models in one go (backend)

  2. How to avoid a messy component (frontend)

I'll start with the 1st one: this one is easy, because in both Livewire and Inertia this is the Laravel part of your code. The core business logic would be exactly the same independent of framework, so any question you have just search for an answer for Laravel. Maybe specify what exactly is your issue, otherwise I can give you a quick tip to use `DB::transaction()` so that you don't break your database if a single query fails.

And for the 2nd one: this is just comes down to your code structure and architecture. Maybe have a look at this repo to have an idea on organizing your React code. A quick tip I can give here is: break your form down logically, save each into their own files, colocate the whole thing and then compose them in one main Form component.

But yeah, it doesn't matter if you save 1 model or 2 models. Keep it simple, abstract away repetition and you'll be fine.

you’re basically fighting 2 separate things here:

  1. how do i save multiple models at once? (backend)

  2. how do i not end up with a monster react component? (frontend)


1) backend – multiple models “in one go”

inertia vs livewire doesn’t matter here. once the request hits laravel it’s just:
“i got some nested data, i need to create/update a few models safely”.

the usual pattern:

  • send one payload that contains everything (invoice + client + provider + items)

  • validate it with nested rules (or a form request)

  • in the controller, wrap the whole thing in a DB::transaction()
    so either all models are saved, or nothing is saved if something blows up

  • create/update: client, provider, invoice, then invoice items

so from laravel’s point of view it’s still just one form submit, just writing to 3–4 tables instead of 1. nothing inertia-specific about it.


2) frontend – avoid the god-component

this is where inertia + react shines if you structure it right.

core idea:

  • keep one single form state (invoice + client + provider + items) in your page or main form component

  • break the UI into small “dumb” sections:

    • <ClientSection />

    • <ProviderSection />

    • <InvoiceMetaSection />

    • <ItemsSection />

  • those sections don’t own state, they just receive value + onChange props

  • the “page” (or main form) is the only one that knows the full shape of the data and is the only place that submits

practically: you still have one form, one submit, one inertia post(), but visually and in code it feels like 3–4 smaller, focused components instead of one giant soup.


mental model that keeps things simple

  • treat the invoice + client + provider as one logical resource in the UI
    (one screen, one save button, one request)

  • treat them as separate models only in the database layer

  • front: composition + one global state

  • back: validation + transaction

doesn’t matter if you’re saving 1 model or 5 — same flow, just slightly more fields.

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.