Skip to content

Cannot access camelCase relationship as a property #8241

@thril

Description

@thril

I am unable to access a relationship as a property if the method name has multiple words camelCased. E.g., the following does not work:

// Project
public function superTalents()
{
    return $this->belongsToMany('My\Domain\Talent', 'project_talents', 'project_id', 'talent_id');
}

// in Tinker or via web app
$project = \My\Domain\Project::find(1);
$project->superTalents->toArray();

Doing the above produces the following fatal:

PHP Fatal error:  Call to a member function toArray() on a non-object in /Users/thril/Projects/Whatev/vendor/psy/psysh/src/Psy/ExecutionLoop/Loop.php(76) : eval()'d code on line 1

And if I access the above as a method call, I get the following:

>>> $project->superTalents();
=> <Illuminate\Database\Eloquent\Relations\BelongsToMany #000000004b7de3e5000000005cd99e3d> {}

However, the following method names do work:

// Project
public function super_talents() {...}
// or
public function talents() {...}

// in Tinker or via web app
$project = \My\Domain\Project::find(1);
$project->super_talents->toArray(); // good to go
// or
$project->talents->toArray(); // good to go

I'm on laravel 5.0.23. This appears to be a bug. Please let me know if I'm missing something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions