laravel 5中的每个记录都有不同的颜色


different colors for each records in laravel 5

我只想为foreach循环中的每个记录添加不同的颜色。我试着添加,但我做不到。下面是我的函数。

public function service()
{
    $result = Order::getService();
    $out = array();
    foreach($result as $row) {
        $out[] = array(
            'id' => $row['orderID'],
            'class'=>'event-special',
            'title' => $row['customer_name'].' - '.$row['order_number'],
            'url' => URL::to('/').'/customer/'.$row['customerID'].'/order/'.$row['orderID'].'/edit',
            'start' => strtotime($row['start_date']) . '000',
            'end' => strtotime($row['end_date']) .'000'
        );
    }
    return json_encode(array('success' => 1, 'result' => $out));
}

有人能帮我吗?

您可以自己创建一组event-special css类,即event-special1event-special2。。。。。。

然后修改代码,为您现有的类添加一个数字

public function service()
{
    $result = Order::getService();
    $out = array();
    $color = 1;
    foreach($result as $row) {
        $out[] = array(
            'id' => $row['orderID'],
            'class'=>'event-special' . $color,
            'title' => $row['customer_name'].' - '.$row['order_number'],
            'url' => URL::to('/').'/customer/'.$row['customerID'].'/order/'.$row['orderID'].'/edit',
            'start' => strtotime($row['start_date']) . '000',
            'end' => strtotime($row['end_date']) .'000'
        );
       $color++;
    }
    return json_encode(array('success' => 1, 'result' => $out));
}