Reputation: 45
I'm new to laravel so sorry if this question seems simple and such.
I want to show the sum of the credit_memo in a given month and year but it shows the error: "number_format() expects parameter 1 to be double, array given " and I don't know what is the source of the error.
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 (just the CreditMemo related ones)
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;
}
}
and the view
<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>
Upvotes: 0
Views: 973
Reputation: 967
It seems this line has some issue
<td class="text-right">{{ number_format($data[$date]['credit_memos'],2) }}</td>
in your view file it seems there are some issue with $data and $date_arr and $date
Could you please check this line..
Upvotes: 1