Skip to content

Eloquent morphToMany() method ignore parameters #56215

Open
@ahbenevento

Description

@ahbenevento

Laravel Version

12.19.3

PHP Version

8.3.12

Database Driver & Version

10.1.16-MariaDB

Description

Illuminate\Database\Eloquent\Concerns\HasRelationships::morphToMany() method ignore the parameters $parentKey and $relatedKey.

Steps To Reproduce

// Into the model
public function roles(): MorphToMany
{
    return $this->morphToMany(
        Role::class,
        'name',
        'table',
        'foreignPivotKey',
        'relatedPivotKey',
        'parentKey',
        'relatedKey'
    );
}

But the SQL result was:

SELECT `roles`.*, `table`.`foreignPivotKey`  AS `pivot_foreignPivotKey`, 
    `table`.`relatedPivotKey`  AS `pivot_relatedPivotKey`, 
    `table`.`name_type`  AS `pivot_name_type` 
FROM `roles` 
    INNER  JOIN `table`  ON `roles`.`relatedKey` = `table`.`relatedPivotKey` 
WHERE `table`.`foreignPivotKey` IN (?)  
    AND `table`.`name_type` = "U"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions