carousel issue in laravel

i am new to laravel and i want to have a carousel of product images on the homepage. carousel.blade.php is imported into index.blade.php, i have the carousel controller, model, etc.
my problem is that the code that i have for the carousel displays 4 images on page (which is what i want), but slides all 4 of them. i want the carousel to slide only 1 image at a time.
here is my carousel.blade.php code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Car Carousel</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        .carousel-item {
            display: none;
            transition: transform 0.6s ease;
        }

        .carousel-item.active {
            display: flex;
        }

        .carousel-item .col-md-3 {
            flex: 1;
            position: relative;
            text-align: center;
        }

        .carousel-caption {
            position: static;
            background-color: rgba(114, 114, 114, 0.5);
            padding: 10px;
            border-radius: 5px;
            margin-top: 10px;
        }

        .car-image {
            width: 100%;
            height: 200px; /* Set a fixed height */
            object-fit: cover; /* Maintain aspect ratio and cover the area */
        }

        .booking-btn {
            margin-top: 10px;
        }

        .btn--base {
            background-color: #fec700;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            text-decoration: none;
        }

        .btn--base:hover {
            background-color: #fec200;
            color: white;
        }
    </style>
</head>
<body>

<!-- Carousel -->
<div id="photoCarousel" class="carousel slide" data-ride="carousel" data-interval="2000">
    <div class="carousel-inner">
        @foreach($cars as $index => $item)
        <div class="carousel-item {{ $index == 0 ? 'active' : '' }}">
            <div class="row">
                @for($i = $index; $i < $index + 4 && $i < count($cars); $i++)
                <div class="col-md-3">
                    <img class="d-block img-fluid car-image" src="{{ get_image($cars[$i]->image ?? '','site-section') ?? '' }}">
                    <div class="carousel-caption d-none d-md-block">
                        <h4>{{ $cars[$i]->car_model ?? "" }}</h4>
                        <p>{{ $cars[$i]->price_standard ?? "" }} EUR {{ __("Per Day") }}</p>
                        <div class="booking-btn">
                            <a href="{{ setRoute('frontend.car.booking.index',$cars[$i]->slug)}}" class="btn--base">{{ __("Book Now") }}</a>
                        </div>
                    </div>
                </div>
                @endfor
            </div>
        </div>
        @endforeach
    </div>
    <a class="carousel-control-prev" href="#photoCarousel" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
    </a>
    <a class="carousel-control-next" href="#photoCarousel" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</div>
<!--Carousel -->

<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Custom Script -->
@push("script")
<script>
    $(document).ready(function() {
        $('#photoCarousel').carousel({
            interval: 10000, // Set the interval to 2 seconds
            cycle: true // Ensure the carousel cycles continuously
        });

        $('#photoCarousel').on('slide.bs.carousel', function (e) {
            var $e = $(e.relatedTarget);
            var idx = $e.index();
            var itemsPerSlide = 1;
            var totalItems = $('.carousel-item').length;

            if (idx >= totalItems-(itemsPerSlide-1)) {
                var it = itemsPerSlide - (totalItems - idx);
                for (var i=0; i<it; i++) {
                    // append slides to end
                    if (e.direction=="left") {
                        $('.carousel-item').eq(i).appendTo('.carousel-inner');
                    }
                    else {
                        $('.carousel-item').eq(0).appendTo('.carousel-inner');
                    }
                }
            }
        });

        // Custom logic to slide one item at a time
        $('#photoCarousel').on('slid.bs.carousel', function () {
            var $activeItem = $('.carousel-item.active');
            var $nextItem = $activeItem.next('.carousel-item');

            if (!$nextItem.length) {
                $nextItem = $('.carousel-item').first();
            }

            $activeItem.removeClass('active');
            $nextItem.addClass('active');
        });
    });
</script>
@endpush

</body>
</html>

expected 1 image to slide every 10 seconds. all 4 images change after 10 seconds

New contributor

Cc868510 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật