ninetysix
8 months ago

What does morphTo actually do?

Posted 8 months ago by ninetysix

Hi,

Sorry if this has already been posted I am new to the forums!

I have recently got into package development, all be it basic package development but I've taken a step out into open source!

I have been referencing other packages in order to keep in line with standards and to actually help me along the way.

I keep seeing morphTo in relationship models. I know about polymorphic relationships and is this related to that? I can't see anything in the Laravel documentation but I can see it in the Laravel API.

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

Above in as an example of this in action.

If someone could tell me what it does and why it's used as I actually feel like I need to use this for what I'm working on.

Thanks in advance!

Please sign in or create an account to participate in this conversation.