Hi I am having problems with relation and database design.
There are three tables called
'articles'
, 'users' ,
'companies'
and articles_authors as polymorphic pivot
with one attribute each called id:
I implements this models
class Article extends Model
{
public function authors()
{
return $this->hasMany('App\Article_Authors','article_id');
}
}
class Article_Authors extends Model
{
public function authorable()
{
return $this->morphTo();
}
public function article(){
return $this->belongsTo('App\Article');
}
}
class User extends Model
{
public function authors()
{
return $this->morphMany('App\Article', 'authorable');
}
}
class Company extends Model
{
public function authors()
{
return $this->morphMany('App\Article', 'authorable');
}
}
and after call $article->authors i get
0
id 1
record_id 2
authorable_id 1
authorable_type "App\User"
created_at "2019-03-22 15:56:38"
updated_at "2019-03-22 15:56:38"
1
id 2
record_id 2
authorable_id 1
authorable_type "App\Company"
created_at "2019-03-22 15:56:59"
updated_at "2019-03-22 15:56:59"
how to call this models now :(