Skip to content

Inconsistent attribute naming of eagerly loaded polymorphic relation #9427

@jarnovanleeuwen

Description

@jarnovanleeuwen

Hello,

The attribute names of eagerly loaded polymorphic relationships are using snake casing, while other relationships (e.g., BelongsTo) are named in camel casing fashion. Example:

class Payment extends Model
{
    public function paymentProfile()
    {
        return $this->belongsTo(PaymentProfile::class);
    }

    public function paymentDetails()
    {
        return $this->morphTo();
    }
}

Behaviour:

$payment = Payment::with('paymentProfile', 'paymentDetails')->first();

var_dump($payment->paymentProfile); // PaymentProfile instance

var_dump($payment->paymentDetails); // NULL

var_dump($payment->payment_details); // SepaDirectDebitPaymentDetails instance

If I remember correctly, it should be independent of the relation type used and should follow the method's name (PaymentDetails in this case).

Jarno

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