To add a where condition on a relation in Laravel Eloquent, you can use the whereHas method. Here's an example of how to modify the user method in the Subscription model to add a where condition on the User model:
public function user()
{
return $this->belongsTo(User::class, 'user_id', 'id')->where('user_type', 10);
}
Instead of using the belongsTo method, you can use the whereHas method to add a where condition on the related User model. Here's an example:
public function user()
{
return $this->hasOne(User::class, 'id', 'user_id')->whereHas('userType', function ($query) {
$query->where('user_type', 10);
});
}
This will return only the User model that has a user_type of 10.