I've got a user and an activity table. A user can have many activities and an activity belongs to a user.

**User**

```
id | name | email

```

**Activity**

```
id | subject_type | subject_id | description

```

I'm having trouble making the belongsTo relationship for activity because it depends on 2 columns. The user id is stored in the subject\_id activiy table with the subject type = user model. So it will look something like this:

```
id |  subject_type    |  subject_id | description
 1 |  App\Models\User |     2       | some description ... 

```

Right now I've come up with:

**Activity model**

```
public function user()
{
    return $this->belongsTo(User::class, 'subject_id')
        ->where('subject_type', User::class);
}

```

but it's wrong because subject\_type is in activity column.