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

NielsNumbers's avatar

Where does renaming happen in Intertia?

My user model has many items, the relation is called niceItems .

   $user->load('niceItems');
    return Inertia::render('Dashboard/Users/Search/Show', compact('user'));

In my VUE app the user object has a property called nice_items. Where does that conversion from camelCase to snake_case happen? I could not find anything in the Interia docs.

0 likes
9 replies
vincent15000's avatar

That's not Inertia that renames niceItems to nice_items.

It's only Laravel that is doint this.

For example if you write a method called getThisWonderfullNameAttribute(), the attribute is accessible via $myModel->this_wonderfull_name.

1 like
vincent15000's avatar

@Elenktik Don't confuse methods and attributes.

When you load a relationship on a model $user->load('niceItems'), Laravel will automatically rename it in snake case. It's the Laravel naming convention.

1 like
NielsNumbers's avatar

@vincent15000 hm, I am not sure if this is true, if dump dd($user->nice_items) after the load call, I receive null, but dd($user->niceItems) returns the collection

1 like
vincent15000's avatar
Level 63

@Elenktik I should have specified --- when you export the datas as a JSON object ---.

1 like
NielsNumbers's avatar

@vincent15000 yes, I just finish readining the page, but I don't see how it relates to my question, as I am not using Accessor, Mutators or Caster.

However, you are right, loaded relationships are transformed to json object from camel case to snake case. I found the paragraph in the docs here:

When an Eloquent model is converted to JSON, its loaded relationships will automatically be included as attributes on the JSON object. Also, though Eloquent relationship methods are defined using "camel case" method names, a relationship's JSON attribute will be "snake case".

1 like

Please or to participate in this conversation.