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

Ligonsker's avatar

Laravel "knows" to fix wrongly capitalized relationship name?

I accidentally named my relationship at first with PascalCase:

public function MyRelationship()
{
    // return ...
}

and also used it in some parts of the code: Auth::user()->MyRelationship->some_column;

But then I renamed the relationship to camelCase:

public function myRelationship()
{
    // return ...
}

but didn't change the code invoking it, and it still worked. I tried to use both myRelationship and MyRelationship and both work

0 likes
4 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Are you developing on mac or windows? Both are case insensitve

1 like
click's avatar

PHP methods are not case sensitive only variables are case sensitive.

From the php.net docs:

Note: Function names are case-insensitive for the ASCII characters A to Z, though it is usually good form to call functions as they appear in their declaration.

https://www.php.net/manual/en/functions.user-defined.php

Sinnbeck's avatar

@click Ah didnt actually know that php itself didnt care. Phpstorm fixes them for me anyways :D

Please or to participate in this conversation.