public static function getByUser($userId, $page) { $result = Capsule::table(Comment::TABLE_NAME)->where('userId', '=', $userId)->orderBy('date', 'desc')->skip(10 * ($page - 1))->take(10)->get(); foreach ($result as $item) { $item->promo = Promo::query()->where('id', '=', $item->promoId)->first(['id', 'title', 'thumbnail']); unset($item->promoId); } return $result; }