Skip to content

Instantly share code, notes, and snippets.

@TiagoSilvaPereira
Created November 19, 2018 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiagoSilvaPereira/6e30c8bdbd6fe71736c645ab1a872479 to your computer and use it in GitHub Desktop.
Save TiagoSilvaPereira/6e30c8bdbd6fe71736c645ab1a872479 to your computer and use it in GitHub Desktop.
Laravel: get the correct model on morphTo relationships (Wrong way)
<?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