Skip to content

Inserting Related Models with Polymorphic Relation #322

@olivervogel

Description

@olivervogel

I just tried the example for the Polymorphic Relation from the docs:

class Photo extends Eloquent {

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

}

class Staff extends Eloquent {

    public function photos()
    {
        return $this->morphMany('Photo', 'imageable');
    }

}

class Order extends Eloquent {

    public function photos()
    {
        return $this->morphMany('Photo', 'imageable');
    }

}

With this code I tried to add a new Photo to a loaded Order:

// load order
$order = Order::find(1);

// create photo
$photo = new Photo
$photo->path = 'foo';

// save photo to the loaded model
$order->photos()->save($photo);

I noticed that imageable_type is not set automatically. Is this not supported and do I have to set it manually or am I doing something wrong here?

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