我有一个订阅者模型
// Subscriber Model
id
user_id
subscribable_id
subscribable_type
public function user()
{
return $this->belongsTo('App\User');
}
public function subscribable()
{
return $this->morphTo();
}
Run Code Online (Sandbox Code Playgroud)
和一个主题模型
// Topic Model
public function subscribers()
{
return $this->morphMany('App\Subscriber', 'subscribable');
}
Run Code Online (Sandbox Code Playgroud)
我希望让所有用户通过订阅者模型,通知他们
通知::发送($ topic-> users,new Notification($ topic));
// Topic Model
public function users()
{
return $this->hasManyThrough('App\User', 'App\Subscriber');
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?