Skip to content
On this page

Naming Conventions

Laravel (Backend – PHP)

  • Use snake_case for:
    • Database columns
    • Eloquent attributes
php
return [
  'first_name' => $user->first_name,
  'email_address' => $user->email_address,
];
  • Use camelCase when passing data to Vue components (see below).

Eloquent JSON Serialization

Vue.js (Frontend – Inertia.js + useForm)

  • Use snake_case in useForm() and camelCase for props coming from Laravel:
php
return Inertia::render('UserDashboard/Index', compact(['firstName', 'emailAddress']));
const props = defineProps(['firstName', 'lastName]);

const form = useForm({
  first_name: props.firstName,
  email_address: props.emailAddress,
});

Why this inconsistency?

  • JavaScript prefers camelCase.
  • Blade/HTML forms historically use snake_case, which aligns with $request->input('first_name') in Laravel.
  • Older Inertia versions auto-converted snake_case from controller to camelCase, but that “magic” was removed due to many issues surrounding this behaviour.
  • Today, be explicit and consistent.

Component Naming in Vue

For props and components in templates, prefer camelCase in JSX and kebab-case in DOM templates. But Vue 3 no longer enforces this strictly.

vue
<WelcomeMessage greetingText="Hi" />

Request Handling (Form Submission)

php
$request->input('first_name');

Working with DTOs

  • DTOs at Laravel should generally use camelCase for DTO keys

✅ Tip: Consistency Table

ContextConventionExample
Laravel codesnake_case$user->first_name
Vue componentsnake_caseform.firstName
Inertia props (PHP)camelCase'firstName' => ...
Inertia props (Vue)camelCaseprops.user.firstName
Form field namecamelCaseform.firstName
DTOcamelCasedto.firstName