Laravel Polymorphic Relations Has Many Through

前端 未结 5 1738
闹比i
闹比i 2020-12-09 09:37

I have a Subscriber Model

// Subscriber Model

id
user_id
subscribable_id
subscribable_type

public function user()
{
    return $this->belongsTo(\'App\\U         


        
5条回答
  •  离开以前
    2020-12-09 09:59

    try this package https://github.com/staudenmeir/eloquent-has-many-deep

    then you could use it like this:

    class Topic extends Model
    {
        use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
        public function users()
        {
            return $this->hasManyDeep(
                'App\User',
                ['App\Subscriber'],
                [null, ['subscribable_type', 'subscribable_id']]
            );
        }
    }
    

提交回复
热议问题