0
我是laravel的新手,所以很抱歉如果這個問題看起來很簡單等。number_format()期望參數1是雙倍的,數組給出
我想在給定的月份和年份顯示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(只貸記通知單相關的)
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>
打印出$ QTOTAL變量,我相信它會是一個數組:) – kejsu