number_format()期望参数1为double,给定数组

时间:2016-04-28 07:57:54

标签: php laravel-5.2

我是laravel的新手,如果这个问题看起来很简单,那就很抱歉。

我想显示给定月份和年份中credit_memo的总和,但它显示错误:“number_format()期望参数1为double,给出数组”并且我不知道是什么源的错误。

CreditMemoModel

<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class CreditMemoModel extends Model{
    public $table = "credit_memo";

    public function getTotalAmount(){
        return $this->credit_memo()->total_amount;
    }
}

?>

CMController(仅与CreditMemo相关)

use App\CreditMemoModel;
$credit_memos = CreditMemoModel::all();
$data               = [];
    foreach($date_arr as $date_index){
      foreach ($credit_memos as $credit_memo) {
            $data[$date_index]['credit_memos'][$credit_memo->total_amount] = 0;
        }
}

和视图

<td>Credit Memo</td>
        @foreach($date_arr as $date)
        <td class="text-right">{{ number_format($data[$date]['credit_memos'],2) }}</td>
        <?php $qtotal += $data[$date]['credit_memos']; ?>
      @endforeach
      <td class="text-right">{{number_format($qtotal, 2)}}</td>

1 个答案:

答案 0 :(得分:1)

这条线似乎有一些问题

<td class="text-right">{{ number_format($data[$date]['credit_memos'],2) }}</td>

在您的视图文件中,似乎存在 $ data $ date_arr 以及 $ date

的问题

请你查一下这句话..