//Controller:
$userBonus = UserBonusModel::with(['event' => function ($query) {
$query->with(['capitals' => function ($query) {
$query->select(['id', 'user_id', 'balance']);
}]);
}])->latest()->paginate();
//Model:
protected static function boot()
{
parent::boot();
static::addGlobalScope(new IsOnScope());
}
public function event()
{
return $this->morphTo();
}