Created
November 19, 2018 15:15
-
-
Save TiagoSilvaPereira/6e30c8bdbd6fe71736c645ab1a872479 to your computer and use it in GitHub Desktop.
Laravel: get the correct model on morphTo relationships (Wrong way)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function project() | |
{ | |
return $this->belongsTo(Project::class, 'commentable_id', 'id'); | |
} | |
public function task() | |
{ | |
return $this->belongsTo(Task::class, 'commentable_id', 'id'); | |
} | |
public function commentable() | |
{ | |
return $this->morphTo(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment