Eloquent Laravel : creating a counter with foreach loop

Solution:

Get first all record and then modify single record using save method like this:

$foos = GanttTask::where('product_id',1)->orderBy('date', 'ASC')->get(); // Get All records

$counter = 1;
foreach($foos as $foo){
    $foo->custom_counter = $counter;
    $counter +=1;
    $foo->save(); // Update each record
}

Good Luck !!!