如何在特定日期添加天数并跳过星期日并在其他日子继续?

I'm trying to create an array of dates. The idea is that I add a number x days and the code, when adding the days skip only Sunday.

This is for laravel and I'm using carbon.

$date = Carbon::now();
   $dates = [];

   for($i = 1 ; $i < 20; $i++){


    if($date->dayOfWeek === Carbon::SATURDAY){

        echo $dates[$i] = $date->addDay(1)->format('d/m/Y') . " - Sunday <br> ";


    } else {


        echo $dates[$i] = $date->addDay(1)->format('d/m/Y') . "<br>";

    }

When i use the constant SUNDAY to skip this date, its not working. It goes on to consider Sunday as Monday

The problem is that you are checking if it's Saturday, and after that you're adding a day to it. You need to echo the date before you add a day to it.

Try this:

if($date->dayOfWeek === Carbon::SUNDAY){ // checking if the current date is a sunday
    echo $dates[$i] = $date->format('d/m/Y') . " - Sunday <br> "; // echo and add the current date to the array
    $date->addDay(1);
} else {
    echo $dates[$i] = $date->format('d/m/Y') . "<br>"; // echo and add the current date to the array
    $date->addDay(1);
}

I got it with this code:

$inicialDate = Carbon::now();
    $newDate = [];

    for($i = 1; $i < 30; $i++)
    {

        $newDate[$i] = $inicialDate->addDay(1);

            if($newDate[$i]->format('l') == "Sunday") 
            {
                $newDate[$i] = $inicialDate->addDay(1);
            }

            echo $newDate[$i]->format('d/m/Y') . " - " . $newDate[$i]->format('l') . "<br>";

    }